A machine-readable index of this documentation for AI agents is available at https://kubevela.io/llms.txt. Markdown versions of documentation pages are available by appending .md to their URLs.
Skip to main content
Version: v1.9

Canary Rollout

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

Before starting​

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

vela addon enable kruise-rollout

First Time Deploy​

Deploy the application as shown below:

cat <<EOF | vela up -f -
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: canary-demo
annotations:
app.oam.dev/publishVersion: v1
spec:
components:
- name: canary-demo
type: webservice
properties:
image: wangyikewyk/canarydemo:v1
ports:
- port: 8090
traits:
- type: scaler
properties:
replicas: 5
- type: gateway
properties:
domain: canary-demo.com
http:
"/version": 8090
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.

$ vela status canary-demo
About:

Name: canary-demo
Namespace: default
Created at: 2023-04-10 14:27:58 +0800 CST
Status: running

Workflow:

mode: DAG-DAG
finished: true
Suspend: false
Terminated: false
Steps
- id: c1cqamr5w6
name: canary-demo
type: apply-component
phase: succeeded

Services:

- Name: canary-demo
Cluster: local Namespace: default
Type: webservice
Healthy Ready:5/5
Traits:
✅ 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:

$ curl -H "Host: canary-demo.com" <ingress-controller-address>/version
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.

Day-2 Canary Release​

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

cat <<EOF | vela up -f -
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: canary-demo
annotations:
app.oam.dev/publishVersion: v2
spec:
components:
- name: canary-demo
type: webservice
properties:
image: wangyikewyk/canarydemo:v2
ports:
- port: 8090
traits:
- type: scaler
properties:
replicas: 5
- type: gateway
properties:
domain: canary-demo.com
http:
"/version": 8090
workflow:
steps:
- type: canary-deploy
name: rollout-20
properties:
weight: 20
- name: suspend-1st
type: suspend
- type: canary-deploy
name: rollout-50
properties:
weight: 50
- name: suspend-2nd
type: suspend
- type: canary-deploy
name: rollout-100
properties:
weight: 100
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. 50% of 5 is 2.5, rounded up to 3, so 3 replicas move to the new version and serve 50% of the traffic. 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:

$ vela status canary-demo
About:

Name: canary-demo
Namespace: default
Created at: 2023-04-10 15:10:56 +0800 CST
Status: workflowSuspending

Workflow:

mode: StepByStep-DAG
finished: false
Suspend: true
Terminated: false
Steps
- id: hqhtsm949f
name: rollout-20
type: canary-deploy
phase: succeeded
- id: umzd2xain9
name: suspend-1st
type: suspend
phase: suspending
message: Suspended by field suspend

Services:

- Name: canary-demo
Cluster: local Namespace: default
Type: webservice
Healthy Ready:5/5
Traits:
✅ rolling-release: workload deployment is completed ✅ scaler ✅ gateway: Visiting URL: canary-demo.com, IP: 192.168.9.103

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

Send 20 requests to the gateway endpoint. About 1 in 5 should come back from Demo: V2; the exact split varies from run to run:

$ for i in $(seq 20); do curl -s -H "Host: canary-demo.com" <ingress-controller-address>/version; echo; done | grep -o "Demo: V[0-9]" | sort | uniq -c
16 Demo: V1
4 Demo: V2

Continue Canary Process​

After checking the canary through your logs and metrics, resume the workflow to continue the rollout.

vela workflow resume canary-demo

Send 20 requests again. The share of Demo: V2 responses rises to about 50%:

$ for i in $(seq 20); do curl -s -H "Host: canary-demo.com" <ingress-controller-address>/version; echo; done | grep -o "Demo: V[0-9]" | sort | uniq -c
10 Demo: V1
10 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 serve non-canary traffic.

image

Canary validation succeed, finished the release​

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

vela workflow resume canary-demo

Send 20 requests again. Every response now comes from Demo: V2:

$ for i in $(seq 20); do curl -s -H "Host: canary-demo.com" <ingress-controller-address>/version; echo; done | grep -o "Demo: V[0-9]" | sort | uniq -c
20 Demo: V2

Canary verification failed, roll back the release​

To cancel the rollout and roll back to the previous version, roll back the workflow:

$ vela workflow rollback canary-demo
Find succeeded application revision %s (PublishVersion: %s) to rollback.
Application spec rollback successfully.
Application status rollback successfully.
Successfully rollback app.
Application outdated revision cleaned up.

The first line is printed as shown, with the %s placeholders unfilled.

Send 20 requests again. Every response comes from Demo: V1:

$ for i in $(seq 20); do curl -s -H "Host: canary-demo.com" <ingress-controller-address>/version; echo; done | grep -o "Demo: V[0-9]" | sort | uniq -c
20 Demo: V1

vela workflow rollback works on a workflow that is suspended, terminated or finished; it refuses one that is still running with can not rollback a running workflow. Here the workflow is suspended between canary steps, so the rollback goes ahead.

Because the Application carries app.oam.dev/publishVersion, the rollback goes to the latest revision whose workflow succeeded. If you release a successful v1, then a v2 that fails, then a v3, rolling back v3 takes you to v1, since v2 never succeeded. Without publishVersion, the rollback restores the spec of the Application's latest revision instead.

Perform canary rollout process on VelaUX​

You can also execute a Canary Rollout process on VelaUX.

First deployment​

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

Day-2 Canary Release​

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

Send 20 requests to the gateway. About 1 in 3 should come back from Demo: V2:

$ for i in $(seq 20); do curl -s -H "Host: canary-demo.com" <ingress-controller-address>/version; echo; done | grep -o "Demo: V[0-9]" | sort | uniq -c
13 Demo: V1
7 Demo: V2

Continue rollout​

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

Rollback​

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