All Products
Search
Document Center

Container Service for Kubernetes:Use ALB Ingresses in Knative

Last Updated:Dec 07, 2023

Application Load Balancer (ALB) runs at the application layer and supports protocols such as HTTP, HTTPS, and Quick UDP Internet Connections (QUIC). ALB offers high elasticity and can process a large amount of network traffic at Layer 7. In addition, ALB supports canary releases based on headers and cookies. This topic describes how to use ALB Ingresses in Knative.

Prerequisites

Step 1: Configure an ALB Ingress

You can configure an ALB Ingress by using one of the following methods:

Method 1: Select an ALB Ingress when you deploy Knative

  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 Components tab, click Deploy Knative.

  4. On the Deploy Knative page, select ALB and select at least two vSwitches. For more information about how to create vSwitches, see Create a vSwitch.

  5. After you complete the configuration, click Deploy.

Method 2: Modify the configuration file of Knative

If Knative is deployed, you can modify the configuration file of Knative to specify an ALB Ingress. For more information about how to deploy Knative, see Deploy Knative and Manage Knative.

  1. Run the following command to modify the configuration file named config-network.yaml:

    kubectl -n knative-serving edit configmap config-network
  2. Refer to the following template to modify the value of the vswitch-ids parameter in the config-network.yaml file. Then, save the change and exit. vswitch-ids specifies the IDs of the vSwitches that are used by the ALB Ingress. You must specify at least two vSwitches IDs and the vSwitches must be deployed in different zones. For more information about the regions and zones that support ALB Ingresses, see Supported regions and zones.

    apiVersion: v1
    data:
      ...
      vswitch-ids: vsw-uf6kbvc7mccqia2pi****,vsw-uf66scyuw2fncpn38**** # Replace the values with the IDs of the two vSwitches deployed in different zones. 
      ...
    kind: ConfigMap
      ...

Step 2: Use the ALB Ingress to access a Service

  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-vpc.cn-beijing.aliyuncs.com/knative-sample/helloworld-go:73fbdd56
            env:
            - name: TARGET
              value: "Knative"
  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 Service named helloworld-go:

    curl -H "host: helloworld-go.default.example.com" http://alb-******.cn-beijing.alb.aliyuncs.com	 # Replace the IP address and domain name with the actual values.

    Expected output:

    Hello Knative!

    The output indicates that the Service can be accessed as normal.