All Products
Search
Document Center

Container Service for Kubernetes:Perform a canary release based on traffic splitting for a Knative Service

Last Updated:Dec 12, 2023

Knative supports canary releases. You can deploy a canary release to split traffic between two application versions based on a specified ratio. This topic describes how to perform a canary release based on traffic splitting for a Knative Service.

Prerequisites

Step 1: Create a Knative 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. On the Services tab of the Knative page, set Namespace to default. Click Create Service to deploy a Service named helloworld-go. After the Service is deployed, 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

    To select an image, click Select Image. In the Select Image dialog box, select an image and click OK. You can also enter the address of a private image registry. The registry address must be in the domainname/namespace/imagename:tag format. In this example, registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go is used.

    Image Version

    Click Select Image Version and select an image version. By default, the latest version is used. In this example, 73fbdd56 is selected.

    Access Protocol

    HTTP and gRPC are supported.

    Note

    Note

    gRPC is developed based on the HTTP/2 standard and Protocol Buffers (protobuf) serialization protocol, and supports various programming languages. Compared with HTTP/1.1, HTTP/2 allows you to send and receive packets more efficiently.

    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.

  4. 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.

  5. Run the following command to access the helloworld-go Service:

    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

  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. On the Services tab, click the name of the Service that you want to manage. On the Service details page, click Create Revision.

  4. Create a revision.

    1. On the Services tab, select the Service that you created and click Details in the Actions column.

    2. Click Create Revision.

    3. On the Basic Information wizard page, click Advanced and set the environment variable of the latest revision to TARGET=Knative.

      11

    4. Click Next.

    5. On the Traffic Splitting Settings wizard page, set the Percent % parameter to 0 for the latest revision and click Create.

      Note

      The sum of traffic ratios of all revisions must be 100.

    6. After the revision is complete, you can find details about the new version on the Services tab.

    7. Run the following command to access the helloworld-go Service:

      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 0 for the new version. This means that all requests to access the helloworld-go Service are sent to the old version.

  5. Modify the traffic splitting ratio to deploy a canary release.

    1. On the Services tab, select the Service that you created and click Details in the Actions column.

    2. Click Split Traffic. In the Split Traffic dialog box, set the Percent % parameter to 50% for both the old and new versions and then click OK.

    3. After the Percent % parameter is set for the Service, you can view the details about the new and old Service versions on the Services tab.

    4. Run the following command to access the Service:

      while true; do curl -H "host: <Default domain name>" http://<Gateway IP address>; slesp 1; done # Replace the gateway IP address and domain name with the actual values.
      Note

      The command runs permanently until you manually terminate it. You can press Ctrl + C to 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 the helloworld-go Service 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.