Knative manages traffic distribution among different Revisions. You can use the console to define the traffic percentage for each Revision and fine-tune the percentage based on your observations until 100% of the Service traffic is routed to the new version. This process completes the phased release.
Prerequisites
Knative is deployed in the cluster. For more information, see Deploy Knative or .
Step 1: Create a Knative service
Log on to the ACK console. In the navigation pane on the left, click Clusters.
On the Clusters page, find the cluster you want and click its name. In the left-side navigation pane, choose .
On the Service Management tab of the Knative page, set Namespace to default. Click Create Service. Then, click Create to deploy a Service named helloworld-go.
The following table describes the key configuration items. For more information about the configuration items, see Deploy a Knative service.
Configuration Item
Description
Service Name
The custom name of the service. In this example, the service name is helloworld-go.
Image Name
You can click Select Image. In the dialog box that appears, select the required image and its version, and then click OK.
You can also enter a private registry. The format is domainname/namespace/imagename:tag. For example, registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:73fbdd56.
Access Protocol
HTTP and gRPC are supported.
NotegRPC is developed based on the HTTP/2 protocol standard and the Protocol Buffers (protobuf) serialization protocol, and supports various programming languages. Compared with HTTP, HTTP/2 is more compact and efficient in 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 for the target service shows Success, the service is deployed.
On the Services page, find the domain name for the
helloworld-goService in the Default Domain column and the gateway IP address in the Gateway column.Run the following command to access the
helloworld-goService:curl -H "Host: <default domain name>" http://<access gateway IP> # Replace <default domain name> and <access gateway IP> with their actual values.Expected output:
Hello World!The output indicates that the Service is created and accessible.
Step 2: Perform a phased release by creating a revision
Log on to the ACK console. In the navigation pane on the left, click Clusters.
On the Clusters page, find the cluster you want and click its name. In the left-side navigation pane, choose .
Create a revision.
On the Service Management tab, click Details in the Actions column for the target service.
Click Create Revision. On the Basic Information page, click Advanced Settings. Set the environment variable for the new revision to
TARGET=Knativeand click Next.
In the Traffic Splitting Settings wizard, set Traffic Percentage for the latest revision to 0 and click Create.
NoteThe sum of the traffic percentages for all revisions must be 100.
After creating the service, select the Services tab to view details about the new service version.
You can run the following command to access the
helloworld-goService:curl -H "Host: <default domain name>" http://<access gateway IP> # Replace <default domain name> and <access gateway IP> with their actual values.Expected output:
Hello World!The output indicates that the Service has been created and is accessible. Because the Traffic Percentage for the new version is 0, requests to the helloworld-go service are still routed to the old version.
Modify the traffic ratio to perform a phased release.
On the Service Management page, click Details in the Actions column for the target service.
Click Split Traffic. In the Split Traffic dialog box, set Traffic Ratio to 50% for both the new and old versions, and click OK.
After you set the service Traffic Percentage, click the Service Management tab to view details about the new and old service versions.
Run the following command to access the Service.
while true; do curl -H "Host: <default domain name>" http://<access gateway IP>; sleep 1; done # Replace <default domain name> and <access gateway IP> with their 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! ...Because the Traffic Ratio is set to 50% for both the new and old versions, traffic to the helloworld-go service is split evenly between them.
You can continue the phased release of the service by adjusting the Traffic Ratio. The phased release is complete when the Traffic Ratio for the new version reaches 100%. During this process, if you encounter any issues with the new version, you can roll back at any time by adjusting the Traffic Ratio.
References
You can implement auto scaling for a Knative Service based on the number of traffic requests. For more information, see Implement auto scaling for a service based on the number of traffic requests.