Knative distributes traffic among different revisions. You can set the traffic percentage for each revision in the console. Then, you can continuously adjust the traffic percentage and monitor the service until 100% of the traffic is routed to the new version, which completes the canary release.
Prerequisites
Knative is deployed in the ACS cluster. For more information, see Deploy Knative.
Step 1: Create a Knative Service
Log on to the ACS console. In the left-side navigation pane, click Clusters.
On the Clusters page, find the cluster that you want to manage and click its ID. In the left-side navigation pane of the cluster details page, choose .
On the Knative page, on the Services tab, set Namespace to default and click Create Service. On the configuration page, create a service named
helloworld-goand click Create.The following table describes the key parameters. For more information about the parameters, see Use Knative to deploy serverless applications.
Parameter
Description
Namespace
Select the namespace to which the Service belongs.
Service Name
Enter a name for the Service. In this example, helloworld-go is used.
Image Name
Click Select images. In the dialog box that appears, select an image and click OK. You can also enter the address of a private registry. The address must be in the domainname/namespace/imagename:tag format. This example uses registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go.
Access Protocol
HTTP and gRPC are supported.
NotegRPC is developed based on the HTTP/2 protocol standard and the Protocol Buffers (Protobuf) serialization protocol. It supports many programming languages. Compared with HTTP, HTTP/2 is more compact and efficient for sending and receiving data.
Container Port
The container port that you want to expose. The port number must be in the range of 1 to 65535.
If the Status column of the Service displays Created, the Service is deployed.
On the Services tab, click the
helloworld-goService and record its domain name and gateway IP address from the Default Domain and Gateway fields, respectively.Run the following command to access the
helloworld-goService:curl -H "Host: <default_domain_name>" http://<gateway_IP_address> # Replace the gateway IP address and domain name with the actual values.Expected output:
Hello World!The output indicates that the Service is created and can be accessed as normal.
Step 2: Create a revision to deploy a canary release
Log on to the ACS console. In the left-side navigation pane, click Clusters.
On the Clusters page, find the cluster that you want to manage and click its ID. In the left-side navigation pane of the cluster details page, choose .
Create a revision.
On the Services tab, select the Service that you created and click Details in the Actions column.
Click Create Revision. On the Basic Information wizard page, click Advanced, set the environment variable of the latest revision to
TARGET=Knative, and click Next.
On the Traffic Splitting Settings wizard page, set the Percent % parameter to 0 for the latest revision and click Create.
NoteThe sum of traffic ratios of all revisions must be 100.
After the revision is complete, you can find details about the new version on the Services tab.
Run the following command to access the
helloworld-goService:curl -H "Host: <default_domain_name>" http://<gateway_IP_address> # Replace the gateway IP address and domain name with the actual values.Expected output:
Hello World!The output indicates that the Service is created and can be accessed as normal. The Percent % parameter is set to
0for the new version. This means that all requests to access the helloworld-go Service are sent to the old version.
Modify the traffic splitting ratio to deploy a canary release.
On the Services tab, select the Service that you created and click Details in the Actions column.
Click Split Traffic. In the Split Traffic dialog box, set the Percent % parameter to
50%for both the old and new versions, then click OK.You can now view the details about the new and old Service versions on the Services tab.
Run the following command to access the Service:
while true; do curl -H "Host: <default_domain_name>" http://<gateway_IP_address>; sleep 1; done # Replace the gateway IP address and domain name with the actual values.NoteThe command runs permanently until you manually terminate it. You can press
Ctrl + Cto terminate the command.Expected output:
Hello World! Hello Knative! Hello World! Hello Knative! Hello World! Hello Knative! ...The Percent % parameter is set to
50%for both the old and new versions. This means that requests to access thehelloworld-goService are evenly distributed to the old and new version.You can change the value of the Percent % parameter to implement canary releases. The new version is completely released if you set the Percent % parameter to
100%for the new version. During the process, you can change the value of the Percent % parameter to roll back if issues are found in the new version.
References
You can automatically scale a Knative service based on the number of requests. For more information, see Configure auto scaling based on the number of requests.