All Products
Search
Document Center

Container Service for Kubernetes:Use the Kourier gateway in Knative

Last Updated:Dec 05, 2023

The Kourier gateway is a lightweight gateway that is based on the Envoy project. You can use the Kourier gateway to distribute traffic across Knative revisions and configure gRPC services, timeouts and retries, Transport Layer Security (TLS) certificates, and external authorization services. This topic describes how to use the Kourier gateway in Knative.

Prerequisites

Step 1: Deploy a Kourier gateway

  1. Log on to the ACK console. In the left-side navigation pane, click Clusters.

  2. On the Clusters page, click the name of the cluster that you want to manage and choose Applications > Knative in the left-side navigation pane.

  3. In the Add-on Component section of the Components tab, find Kourier and click Deploy in the Actions column. In the message that appears, click Confirm.

    If the Status column of the Kourier component displays Deployed, the component is deployed.

Step 2: Use the Kourier gateway to access a Service

In this example, a Knative Service named helloworld-go is used.

Scenario 1: Use the Kourier gateway to access a Knative Service over HTTP

  1. Log on to the ACK console. In the left-side navigation pane, click Clusters.

  2. On the Clusters page, click the name of the cluster that you want to manage and choose Applications > Knative in the left-side navigation pane.

  3. On the Services tab of the Knative page, set Namespace to default, click Create from Template, copy the following YAML content to the template editor, and then click Create.

    The template creates a Service named helloworld-go.

    apiVersion: serving.knative.dev/v1
    kind: Service
    metadata:
      name: helloworld-go
    spec:
      template:
        spec:
          containers:
          - image: registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:73fbdd56
            env:
            - name: TARGET
              value: "Knative"

    If the Status column of the Service displays Created, the Service is deployed.

  4. On the Services page, record the domain name and gateway IP address of the helloworld-go Service in the Default Domain and Gateway columns, respectively.

  5. Run the following command to access the helloworld-go Service:

    curl -H "host: helloworld-go.default.example.com" http://8.141.XX.XX # Specify the actual gateway IP address and domain name that you obtained.

    Expected output:

    Hello Knative!

    The output indicates that the Knative Service can be accessed over HTTP.

Scenario 2: Use the Kourier gateway to access the Knative Service over HTTPS

  1. The template creates a Service named helloworld-go.

    For more information, see Step 3.

  2. Generate a TLS certificate.

    1. Run the following command to generate a TLS certificate:

      openssl genrsa -out tls.key 4096
      openssl req -subj "/CN=*.example.com/L=*.example.com" -sha256  -new -key tls.key -out tls.csr
      echo subjectAltName = DNS:helloworld-go.default.example.com,DNS:helloworld-go.default.example.cn > extfile.cnf
      openssl x509 -req -days 3650 -sha256 -in tls.csr -signkey tls.key -out tls.crt -extfile extfile.cnf
    2. Run the following command to create a Secret in the cluster based on the TLS certificate that you generated:

      kubectl -n knative-serving create secret tls kourier-cert --key tls.key --cert tls.crt
  3. Run the following command to check whether a Deployment named net-kourier-controller exists in the knative-serving namespace:

    kubectl get deployments -n knative-serving
  4. Run the following command to configure the certificate:

    kubectl -n knative-serving edit deployment net-kourier-controller

    On the net-kourier-controller configuration page, specify the following parameters:

    • CERTS_SECRET_NAMESPACE: Set the value to the namespace to which the Secret that you created belongs.

    • CERTS_SECRET_NAME: Set the value to the name of the Secret that you created.

    ...
       spec:
          containers:
          - env:
            - name: CERTS_SECRET_NAMESPACE
              value: knative-serving 
            - name: CERTS_SECRET_NAME
              value: kourier-cert
    ...
    1. Run the following command to check the status of net-kourier-controller:

      kubectl -n knative-serving get po

      Expected output:

      NAME                               READY   STATUS    RESTARTS   AGE
      net-kourier-controller-******   1/1     Running   0          10s
  5. Run the following command to access the Knative Service over HTTPS:

    curl -H "host: helloworld-go.default.example.com" -k --cert tls.crt --key tls.key //8.141.XX.XX # Specify the actual gateway IP address and domain name that you obtained.

    Expected output:

    Hello Knative!

    The output indicates that the Knative Service can be accessed over HTTPS.