All Products
Search
Document Center

Alibaba Cloud Service Mesh:Perform a canary release based on traffic splitting for a Knative Service by using Knative on ASM

Last Updated:Feb 29, 2024

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-side navigation pane, click Clusters.

  2. On the Clusters page, click the name of the cluster that you want to manage and choose Applications > Knative in the left-side navigation pane.

  3. Click the Services tab. In the list of Services, find the desired Service and click its name. In the upper-right corner of the displayed page, click Create Revision.

  4. In the Basic Information step, click Advanced in the lower part. Then, click Add next to Environment Variables, and set Type to Custom, Variable Key to TARGET, and Value/ValueFrom to Knative on ASM. Then, click Next.

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

    Note

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

    After the Revision is created, click the Services tab. In the list of Services, click the name of the desired Service. In the Revision Information section, you can view the details of the created Revision.

  6. Run the following command to access the service:

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

    Expected output:

    Hello World!

    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-side navigation pane, click Clusters.

  2. On the Clusters page, click the name of the cluster that you want to manage and choose Applications > Knative in the left-side navigation pane.

  3. Click the Services tab. In the list of Services, click the name of the desired Service. In the upper-right corner of the displayed page, click Split Traffic. In the Split Traffic dialog box, set Percent % to 50 for both the latest Revision and the previous Revision and click OK.

    After the successful configuration of the traffic splitting percentage, click the Services tab. In the list of Services, click the name of the desired Service. In the Revision Information section of the displayed page, you can view the details of the new and previous Revisions.

  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 World!
    Hello Knative on ASM!
    Hello World!
    Hello World!
    Hello World!
    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 World!
    Hello Knative on ASM!
    Hello World!
    Hello Knative on ASM!
    Hello Knative on ASM!
    Hello World!
    Hello World!

    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. Gradually adjust the settings of the Percent % parameter until the traffic percentage for the new Revision reaches 100%.

    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 expected output indicates that all requests to access the helloworld-go service are sent to the new Revision. This indicates that the canary release for the service is successfully performed.

Related operations

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 autoscaling of pods based on the number of requests.