Route Knative traffic with an ALB Ingress

Updated at:

Route HTTP, HTTPS, and QUIC traffic to Knative Services using an ALB Ingress. ALB provides a fully managed, maintenance-free Layer 7 load balancing service with automatic scaling and traffic splitting for applications that require fine-grained routing.

Prerequisites

Step 1: Deploy the ALB Ingress

Deploy an ALB Ingress by creating a new ALB instance or using an existing one.

Auto-create an ALB instance

Configure the ALB Ingress during initial Knative deployment or by modifying an existing deployment's configuration file.

During deployment

  1. Log on to the ACS console. In the left navigation pane, click Clusters.

  2. On the Clusters page, click the name of the target cluster. In the left navigation pane, choose Applications > Knative.

  3. On the Add-ons tab, click Deploy Knative. On the deployment page, select ALB as the service gateway, select at least two VSwitches, and follow the on-screen instructions to deploy Knative.

    To create a vSwitch, follow Create a vSwitch.

Modify the configuration file

To configure the ALB Ingress for an existing deployment, modify the Knative configuration file. To deploy Knative, follow Deploy Knative.

  1. Run the following command to edit the config-network.yaml file.

    kubectl -n knative-serving edit configmap config-network
  2. Modify and save the config-network.yaml file as follows.

    Modify ingress.class: alb.ingress.networking.knative.dev and set vswitch-ids, and then save and close the config-network file to complete the ALB gateway configuration. For information about the regions and zones that ALB supports, see Regions and zones supported by ALB.

    apiVersion: v1
    data:
      ...
      ingress.class: alb.ingress.networking.knative.dev # Indicates that ALB is used as the Ingress controller.
      vswitch-ids: vsw-uf6kbvc7mccqia2pi****,vsw-uf66scyuw2fncpn38**** # Replace with the IDs of two vSwitches that you have created in different zones. The system automatically binds these vSwitches when creating the ALB.
      intranet: "true" # Also creates an internal-facing ALB instance.
      internet: "true" # Default: true, indicates that an internet-facing ALB instance is created. If set to false, no internet-facing ALB is created.
      ...
    kind: ConfigMap
    metadata:
      name: config-network
      namespace: knative-serving
      ...
    Important

    If only the internal-facing ALB is enabled, the Knative Service must be set to internal access only. To do so, set the label networking.knative.dev/visibility: cluster-local.

Use an existing ALB instance

To use an existing ALB instance, modify the Knative configuration file.

  1. Run the following command to edit the config-network.yaml file.

    kubectl -n knative-serving edit configmap config-network
  2. Modify and save the config-network.yaml file as follows.

    In the configuration file, modify ingress.class: alb.ingress.networking.knative.dev and set albconfig to an existing ALB. In this case, vswitch-ids does not need to be configured.

    apiVersion: v1
    data:
      ...
      ingress.class: alb.ingress.networking.knative.dev # Indicates that ALB is used as the Ingress controller.
      albconfig: alb-dev-albconfig # Specify and reuse the name of an existing internet-facing ALBConfig.
      intranet-albconfig: alb-dev-intranet-albconfig # Specify and reuse the name of an existing internal-facing ALBConfig.
    ...
    kind: ConfigMap
    metadata:
      name: config-network
      namespace: knative-serving
      ...

Step 2: Access the service via ALB Ingress

  1. Log on to the ACS console. In the left navigation pane, click Clusters.

  2. On the Clusters page, click the name of the target cluster. In the left navigation pane, choose Applications > Knative.

  3. On the Knative page, click the Services tab, select default from Namespace, click Create from Template, paste the following YAML example into the template, and then click Create.

    The following example YAML creates a Knative 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 # Replace the region with the actual region you use.
            env:
            - name: TARGET
              value: "Knative"
  4. On the Services page, get the domain and gateway address of the helloworld-go service from the Default Domain and Access Gateway columns, respectively.

  5. Run the following command to access the helloworld-go service.

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

    Expected output:

    Hello Knative!

(Optional) Step 3: View service monitoring data

Knative provides built-in observability. On the Knative page, click the Monitoring Dashboards tab to view monitoring data. View the Knative Service monitoring dashboard.

image.png

Related documents