Perform a canary release based on traffic splitting for a Knative Service by using Knative on ASM

Updated at:

If you face compatibility and stability challenges when you release a new version of your application during iterative development, you can perform a canary release based on traffic splitting for a Knative Service by using Knative on ASM. ASM is short for Service Mesh. When you create a Knative Service, Knative automatically creates the first Revision for the Service. Whenever the configuration of the Knative Service updates or changes, Knative creates a new Revision and you can modify the percentages of traffic that is distributed to different Revisions to accurately verify the new Revision in real time. This significantly reduces potential risks that may arise from the large-scale deployment of the new Revision, helping you ensure service continuity and user experience and discover and fix issues in a timely manner.

Prerequisites

A Knative Service is created by using Knative on ASM. For more information, see Use Knative on ASM to deploy a serverless application.

Note

In this topic, the default domain name example.com is used to demonstrate how to perform a canary release for a Service. If you need to use a custom domain name, see Set a custom domain name in Knative on ASM.

Create a Revision in the ACK console

  1. Log on to the ACK console. In the left navigation pane, click Clusters.

  2. On the Clusters page, click the name of your cluster. In the left navigation pane, click Applications > Knative.

  3. Click the Services tab, click the name of the target service in the service list, and then click Create Revision in the upper-right corner.

  4. In the Basic Information step, click Advanced. To the right of Environment Variables, click Add. Set Type to Custom, Variable Name to TARGET, and Value/ValueFrom to Knative on ASM. Then, click Next.

  5. In the Traffic Splitting Settings step, set Percent % for the Latest Revision to 0 and for the old revision to 100. Then, click Create.

    Note

    The sum of traffic percentages for all Revisions must be 100%.

    After the revision is created, you can click the Services tab, click the name of the target service, and then view the details of the new revision in the Revision Information section.

  6. Run the following command to access the service:

    curl http://helloworld-go.default.example.com

    Expected output:

    Hello Knative!

    The expected output indicates that all requests to access the helloworld-go service are sent to the previous Revision.

Modify the traffic splitting percentage to perform a canary release for the Service

  1. Log on to the ACK console. In the left navigation pane, click Clusters.

  2. On the Clusters page, click the name of your cluster. In the left navigation pane, click Applications > Knative.

  3. Click the Services tab, click the name of the target service in the service list, and then click Split Traffic in the upper-right corner. In the Split Traffic dialog box, set the traffic percentage for both the new and old revisions to 50, and then click OK.

    After you configure the traffic split, on the Services tab, click the target service name to view the details for both the new and old revisions in the Revision Information section.

  4. Run the following command to access the service:

    for i in `seq 20`; do curl http://helloworld-go.default.example.com; done;

    Expected output:

    Hello Knative on ASM!
    Hello Knative on ASM!
    Hello Knative!
    Hello Knative on ASM!
    Hello Knative!
    Hello Knative!
    Hello Knative!
    Hello Knative on ASM!
    Hello Knative on ASM!
    Hello Knative on ASM!
    Hello Knative on ASM!
    Hello Knative on ASM!
    Hello Knative on ASM!
    Hello Knative!
    Hello Knative on ASM!
    Hello Knative!
    Hello Knative on ASM!
    Hello Knative on ASM!
    Hello Knative!
    Hello Knative!

    The expected output indicates that requests to access the helloworld-go service are almost evenly distributed to the new Revision and the previous Revision.

  5. Continue to adjust the traffic split by clicking Split Traffic until 100% of the traffic is routed to the new revision.

    During the process, you can change the value of the Percent % parameter to perform a rollback if you find an issue in the new Revision.

  6. Run the following command to access the service again:

    for i in `seq 20`; do curl http://helloworld-go.default.example.com; done;

    Expected output:

    Hello Knative on ASM!
    Hello Knative on ASM!
    Hello Knative on ASM!
    Hello Knative on ASM!
    Hello Knative on ASM!
    Hello Knative on ASM!
    Hello Knative on ASM!
    Hello Knative on ASM!
    Hello Knative on ASM!
    Hello Knative on ASM!
    Hello Knative on ASM!
    Hello Knative on ASM!
    Hello Knative on ASM!
    Hello Knative on ASM!
    Hello Knative on ASM!
    Hello Knative on ASM!
    Hello Knative on ASM!
    Hello Knative on ASM!
    Hello Knative on ASM!
    Hello Knative on ASM!

    The output shows that all requests are now handled by the new revision, which receives 100% of the traffic, indicating the canary release is complete.

Related documents

Knative Serving adds the Queue Proxy container to each pod. The Queue Proxy container sends the concurrency metrics of the application containers to Knative Pod Autoscaler (KPA). After KPA receives the metrics, KPA automatically adjusts the number of pods provisioned for a Deployment based on the number of concurrent requests and related autoscaling algorithms. For more information, see Enable request-based pod autoscaling.