Route Knative traffic with an ALB Ingress
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
-
You have deployed Knative in the ACS cluster.
-
The ALB Ingress controller is installed.
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
-
Log on to the ACS console. In the left navigation pane, click Clusters.
-
On the Clusters page, click the name of the target cluster. In the left navigation pane, choose .
-
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.
Run the following command to edit the
config-network.yamlfile.kubectl -n knative-serving edit configmap config-networkModify and save the
config-network.yamlfile as follows.Modify
ingress.class: alb.ingress.networking.knative.devand setvswitch-ids, and then save and close theconfig-networkfile 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 ...ImportantIf 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.
Run the following command to edit the
config-network.yamlfile.kubectl -n knative-serving edit configmap config-networkModify and save the
config-network.yamlfile as follows.In the configuration file, modify
ingress.class: alb.ingress.networking.knative.devand setalbconfigto an existing ALB. In this case,vswitch-idsdoes 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
-
Log on to the ACS console. In the left navigation pane, click Clusters.
-
On the Clusters page, click the name of the target cluster. In the left navigation pane, choose .
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"On the Services page, get the domain and gateway address of the
helloworld-goservice from the Default Domain and Access Gateway columns, respectively.Run the following command to access the
helloworld-goservice.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.

Related documents
-
Enable a custom domain for your Knative Service. Use a custom domain.
-
Configure an HTTPS certificate for your Knative Service. Configure an HTTPS certificate.
-
Deploy a gRPC service in Knative to improve network efficiency. Deploy a gRPC service in Knative.
-
Configure a probe to monitor the health of your Knative Service. Configure a port probe in Knative.