We recommend that you use Application Load Balancer (ALB) Ingresses to route traffic of Knative Services for large-scale web applications, applications that require fine-grained traffic routing or auto scaling, and applications with complex routing requirements for HTTP/HTTPS requests. 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. ALB Ingresses is a fully managed and O&M-free gateway that supports auto scaling and multiple canary release rules.
Prerequisites
Knative is deployed in your cluster. For more information, see Deploy Knative.
Step 1: Deploy an ALB Ingress
When you deploy an ALB Ingress in Knative, you can use the ALB instance automatically created by Knative or specify an existing ALB instance.
An ALB instance is automatically created when you deploy an ALB Ingress
You can configure an ALB Ingress during the deployment of Knative. If Knative is deployed, you can modify the configuration file of Knative to configure an ALB Ingress.
Configure an ALB Ingress when you deploy Knative
Log on to the ACK console. In the left-side navigation pane, click Clusters.
On the Clusters page, find the cluster that you want to manage and click its name. In the left-side pane, choose .
On the Components tab, click Deploy Knative. On the Deploy Knative page, select ALB and select at least two vSwitches. Follow the instructions on the page to deploy Knative.
For more information about how to create vSwitches, see Create and manage a vSwitch.
Modify the configuration file of Knative to configure an ALB Ingress
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 in an ACK cluster and Deploy Knative in an ACK Serverless cluster.
Run the following command to modify the config-network.yaml file:
kubectl -n knative-serving edit configmap config-network
Refer to the following template to modify and save the config-network.yaml file.
Modify
ingress.class: alb.ingress.networking.knative.dev
, configure thevswitch-ids
parameter, and save theconfig-network
file and exit. For more information about the regions and zones that support ALB Ingresses, see Regions and zones in which ALB is available.apiVersion: v1 data: ... ingress.class: alb.ingress.networking.knative.dev # Specify the ALB Ingress controller. vswitch-ids: vsw-uf6kbvc7mccqia2pi****,vsw-uf66scyuw2fncpn38**** # Replace with the IDs of the two vSwitches that you created in different zones. The system automatically binds the vSwitches when you create an ALB instance. ... kind: ConfigMap metadata: name: config-network namespace: knative-serving ...
Use an existing ALB instance to configure an ALB Ingress
You can modify the configuration file of Knative to configure an ALB Ingress by using an existing ALB instance.
Run the following command to modify the config-network.yaml file:
kubectl -n knative-serving edit configmap config-network
Modify and save the config-network.yaml file based on the following template.
Modify
ingress.class: alb.ingress.networking.knative.dev
in the configuration file and setalbconfig
to an existing ALB Ingress. You do not need to configure thevswitch-ids
parameter.apiVersion: v1 data: ... ingress.class: alb.ingress.networking.knative.dev # Specify the ALB Ingress controller. albconfig: alb-dev-albconfig # Specify the name of an existing AlbConfig. You must specify this parameter if you use an existing ALB Ingress. ... kind: ConfigMap metadata: name: config-network namespace: knative-serving ...
Step 2: Use the ALB Ingress to access a Service
Log on to the ACK console. In the left-side navigation pane, click Clusters.
On the Clusters page, find the cluster that you want to manage and click its name. In the left-side navigation pane, choose .
On the Services tab of the Knative page, select default from the Namespace drop-down list, click Create from Template, copy the following YAML content to the code 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"
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.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!
(Optional) Step 3: View the Knative monitoring dashboard
Knative provides out-of-the-box monitoring features. On the Knative page, click the Monitoring Dashboards tab to view the monitoring data of the specified Service. For more information about how to enable the Knative monitoring dashboard, see View the Knative monitoring dashboard.
References
You can specify custom domain names for Knative Services. For more information, see Configure a custom domain name.
You can configure a certificate to access Knative Services over HTTPS. For more information, see Configure a certificate to access Services over HTTPS.
You can deploy a gRPC Service in Knative to improve network efficiency. For more information, see Deploy a gRPC Service in Knative.
You can configure probes to monitor the health status and availability of Knative Services. For more information, see Configure port probing in Knative.
If you want to connect an elastic container instance to the Internet, you must associate an elastic IP address (EIP) with the elastic container instance. For more information, see Associate an EIP with the elastic container instance on which a Knative Service runs.