Route Knative traffic with an ALB Ingress

更新时间:
复制 MD 格式

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 in the following format.

    After you modify ingress.class: alb.ingress.networking.knative.dev and set vswitch-ids, save the config-network file to configure the ALB gateway. For more 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 # Specifies that ALB is used as the Ingress controller.
      vswitch-ids: vsw-uf6kbvc7mccqia2pi****,vsw-uf66scyuw2fncpn38**** # Replace the parameter value with the IDs of two vSwitches that you created in different zones. The system automatically attaches the vSwitches when it creates the ALB instance.
      intranet: "true" # Creates a private ALB instance.
      internet: "true" # The default value is true, which creates a public ALB instance. If you set this to false, a public ALB instance is not created.
      ...
    kind: ConfigMap
    metadata:
      name: config-network
      namespace: knative-serving
      ...
    Important

    If you enable only a private ALB instance, you must enable internal-only access for the Knative service. To do this, 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 in the following format.

    In the configuration file, include the line ingress.class: alb.ingress.networking.knative.dev and set albconfig to an existing ALB instance. In this case, you do not need to configure vswitch-ids.

    apiVersion: v1
    data:
      ...
      ingress.class: alb.ingress.networking.knative.dev # Specifies that ALB is used as the Ingress controller.
      albconfig: alb-dev-albconfig # Specifies and reuses the name of an existing public ALB instance.
    ...
    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. Set Namespace to default, and then click Create from Template. Paste the following sample YAML into the template, and then click Create.

    The following sample 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.
            env:
            - name: TARGET
              value: "Knative"
  4. On the Services page, obtain the domain name and gateway address of the helloworld-go service from the Default Domain Name and Access Gateway columns.

  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 the gateway IP address and domain name with the actual values.

    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