Canary Rollout

In this section, we will introduce how to canary rollout a container service.

Enable kruise-rollout addon, our canary rollout capability relies on the rollouts from OpenKruise.

  1. vela addon enable kruise-rollout

Deploy the application as shown below:

  1. cat <<EOF | vela up -f -
  2. apiVersion: core.oam.dev/v1beta1
  3. kind: Application
  4. metadata:
  5. name: canary-demo
  6. annotations:
  7. app.oam.dev/publishVersion: v1
  8. spec:
  9. components:
  10. - name: canary-demo
  11. type: webservice
  12. properties:
  13. image: wangyikewyk/canarydemo:v1
  14. ports:
  15. - port: 8090
  16. traits:
  17. - type: scaler
  18. properties:
  19. replicas: 5
  20. - type: gateway
  21. properties:
  22. domain: canary-demo.com
  23. http:
  24. "/version": 8090
  25. EOF

The first deployment is a default way to deploy an application. You can check the status of the application to ensure it’s running before proceeding to the next step.

  1. $ vela status canary-demo
  2. About:
  3. Name: canary-demo
  4. Namespace: default
  5. Created at: 2023-04-10 14:27:58 +0800 CST
  6. Status: running
  7. Workflow:
  8. mode: DAG-DAG
  9. finished: true
  10. Suspend: false
  11. Terminated: false
  12. Steps
  13. - id: c1cqamr5w6
  14. name: canary-demo
  15. type: apply-component
  16. phase: succeeded
  17. Services:
  18. - Name: canary-demo
  19. Cluster: local Namespace: default
  20. Type: webservice
  21. Healthy Ready:5/5
  22. Traits:
  23. scaler gateway: No loadBalancer found, visiting by using 'vela port-forward canary-demo'

If you have enabled velaux addon, you can view the application topology graph that all v1 pods are ready now.

image

If you have already installed an ingress controller (or you can install one by enable the ingress-nginx addon), you can access the gateway endpoint with the specific host by:

  1. $ curl -H "Host: canary-demo.com" <ingress-controller-address>/version
  2. Demo: V1

The host canary-demo.com is aligned with the gateway trait in your application, you can also configure it in your /etc/hosts to use the host url for visiting.

Let’s modify the image tag of the component, from v1 to v2 as follows:

  1. cat <<EOF | vela up -f -
  2. apiVersion: core.oam.dev/v1beta1
  3. kind: Application
  4. metadata:
  5. name: canary-demo
  6. annotations:
  7. app.oam.dev/publishVersion: v2
  8. spec:
  9. components:
  10. - name: canary-demo
  11. type: webservice
  12. properties:
  13. image: wangyikewyk/canarydemo:v2
  14. ports:
  15. - port: 8090
  16. traits:
  17. - type: scaler
  18. properties:
  19. replicas: 5
  20. - type: gateway
  21. properties:
  22. domain: canary-demo.com
  23. http:
  24. "/version": 8090
  25. workflow:
  26. steps:
  27. - type: canary-deploy
  28. name: rollout-20
  29. properties:
  30. weight: 20
  31. - name: suspend-1st
  32. type: suspend
  33. - type: canary-deploy
  34. name: rollout-50
  35. properties:
  36. weight: 50
  37. - name: suspend-2nd
  38. type: suspend
  39. - type: canary-deploy
  40. name: rollout-100
  41. properties:
  42. weight: 100
  43. EOF

As we can see, in this update, we have also configured a canary-deploy workflow. This workflow includes 5 steps and splits the entire process into 3 stages. Here’s an overview about what will happen of the three stages:

  1. In the first stage, the deployment will be updated with 20% of the total replicas. In our example, since we have a total of 5 replicas, 1 replica will be updated to the new version and serve 20% of the traffic. The upgrade process will then wait for a manual approval before moving on to the next stage.
  2. Once the first stage has been approved, the second stage will begin. During this stage, 50% of the total replicas will be updated to the new version. In our example, this means that 2.5 replicas will be updated, which is rounded up to 3. These 3 replicas will serve 50% of the traffic, and the upgrade process will once again wait for a manual approval before moving on to the final stage.
  3. In the final stage, all replicas will be updated to the new version and serve 100% of the traffic

Check the status of the application:

  1. $ vela status canary-demo
  2. About:
  3. Name: canary-demo
  4. Namespace: default
  5. Created at: 2023-04-10 15:10:56 +0800 CST
  6. Status: workflowSuspending
  7. Workflow:
  8. mode: StepByStep-DAG
  9. finished: false
  10. Suspend: true
  11. Terminated: false
  12. Steps
  13. - id: hqhtsm949f
  14. name: rollout-20
  15. type: canary-deploy
  16. phase: succeeded
  17. - id: umzd2xain9
  18. name: suspend-1st
  19. type: suspend
  20. phase: suspending
  21. message: Suspended by field suspend
  22. Services:
  23. - Name: canary-demo
  24. Cluster: local Namespace: default
  25. Type: webservice
  26. Healthy Ready:5/5
  27. Traits:
  28. rolling-release: workload deployment is completed scaler gateway: Visiting URL: canary-demo.com, IP: 192.168.9.103
  29. - Name: canary-demo
  30. Cluster: local Namespace: default
  31. Type: webservice
  32. Healthy Ready:5/5
  33. Traits:
  34. scaler gateway: No loadBalancer found, visiting by using 'vela port-forward canary-demo'

The application’s status is currently set to workflowSuspending, which means that the first step has been completed and the workflow is now waiting for manual approval.

View the topology graph again to confirm that a new v2 pod has been created to serve canary traffic. Meanwhile, the remaining 4 v1 pods are still running and serving non-canary traffic. image

Access the gateway endpoint again. You will find that there is approximately a 20% chance of seeing the Demo: v2 result.

  1. $ curl -H "Host: canary-demo.com" <ingress-controller-address>/version
  2. Demo: V2

After verify the success of the canary version through business-related metrics, such as logs, metrics, and other means, you can resume the workflow to continue the process of rollout.

  1. vela workflow resume canary-demo

Access the gateway endpoint again multi times. You will find out the chance (50%) to meet result Demo: v2 is highly increased.

  1. $ curl -H "Host: canary-demo.com" <ingress-controller-address>/version
  2. Demo: V2

View topology graph again, you will see the workload updated 3 replicas to v2, and this pod will serve the canary traffic. Meanwhile, 2 pods of v1 are still running and server non-canary traffic.

image

In the end, you can resume again to finish the rollout process.

  1. vela workflow resume canary-demo

Access the gateway endpoint again multi times. You will find out the result always is Demo: v2.

  1. $ curl -H "Host: canary-demo.com" <ingress-controller-address>/version
  2. Demo: V2

If you want to cancel the rollout process and rollback the application to the latest version, after manually check. You can rollback the rollout workflow:

  1. $ vela workflow rollback canary-demo
  2. Application spec rollback successfully.
  3. Application status rollback successfully.
  4. Successfully rollback rolloutApplication outdated revision cleaned up.

Access the gateway endpoint again. You can see the result is always Demo: V1.

  1. $ curl -H "Host: canary-demo.com" <ingress-controller-address>/version
  2. Demo: V1

Any rollback operation in middle of a runningWorkflow will rollback to the latest succeeded revision of this application. So, if you deploy a successful v1 and upgrade to v2, but this version didn’t succeed while you continue to upgrade to v3. The rollback of v3 will automatically to v1, because release v2 is not a succeeded one.

You can also execute a Canary Rollout process on VelaUX.

To begin, create an application with a webservice component and set its image to wangyikewyk/canarydemo:v1, as shown in the image below:

image

Next, add a scaler trait for this component and set the replica number to 3, as shown below:

image

Finally, configure a gateway for the component and set the hostname and traffic route, as illustrated in the image:

image

After clicking the deploy button, the application will be deployed, and you can check its status on the resource topology page, as shown below:

image

To update the component, change the image to wangyikewyk/canarydemo:v2:

image

Next, click the deploy button then click Enable Canary Rollout button to create a new canary rollout workflow, as shown below:

image

Set the batches to 3 to perform a Canary Rollout of the application with 3 batches:

image

You will see the new created workflow is as shown below, click the save button to save it.

image

The rollout process is divided into three steps, with each step releasing 1/3 replicas and traffic to the new version. A manual approval step is between two canary-deploy steps. You can also modify the weight of every Canary Rollout step.

Click deploy again and choose the Default Canary Workflow to begin the rollout process as shown:

image

After the first step is complete, 1 replica will be updated to v2, as shown below:

image

You can try to access the gateway using the following command, and you will have a 1/3 chance of getting the Demo: V1.

  1. $ curl -H "Host: canary-demo.com" <ingress-controller-address>/version
  2. Demo: V1

To continue the rollout process, click the continue button on the workflow page:

image

You will find that 2 replicas have been updated to the new version:

image

To terminate the rolling process and rollback the application to version v1, click the rollback button:

image

You will find that all replicas have been rolled back to v1:

image

Last updated on Aug 4, 2023 by Daniel Higuero