--- title: Canary Rollout --- ## Before starting 1. Please make sure you have read the doc of about [the basic deployment of Kubernetes resources](./k8s-object.mdx). 2. Make sure you have already enabled the [`kruise-rollout`](../reference/addons/kruise-rollout.md) addon, our canary rollout capability relies on the [rollouts from OpenKruise](https://github.com/openkruise/rollouts). ```shell vela addon enable kruise-rollout ``` 3. Please make sure one of the [ingress controllers](https://kubernetes.github.io/ingress-nginx/deploy/) is available in your Kubernetes cluster. You can also enable the [ingress-nginx](../reference/addons/nginx-ingress-controller.md) or [traefik](../reference/addons/traefik.md) addon if you don't have any: ```shell vela addon enable ingress-nginx ``` Please refer to [the addon doc](../reference/addons/nginx-ingress-controller.md) to get the access address of gateway. 4. Some of the commands such as `rollback` relies on vela-cli `>=1.5.0-alpha.1`, please upgrade the command line for convenience. You don't need to upgrade the controller. ## Limitation Kubernetes resources can be anything, this canary rollout works for the scenarios within the following limits: 1. The Kubernetes resources contain a service pointing to the workload along with an ingress routing to the service. 2. Workloads supported including Kubernetes Deployment, StatefulSet, and [OpenKruise Cloneset](https://openkruise.io/docs/user-manuals/cloneset/). That means the workload specified must be one of these three types. ### First deployment When you want to use the canary rollout, you need to add the `kruise-rollout` trait at the first time, this configuration will take effect at next release process. Deploy the application with traits like below: ```shell cat </version Demo: V1 ``` ## Day-2 Canary Release Modify the image tag from `v1` to `v2` as follows: ```shell cat </version Demo: V2 ``` ## Continue Canary Process 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. ```shell vela workflow resume canary-demo ``` Access the gateway endpoint again multi times. You will find out the chance to meet result `Demo: v2` is highly increased, almost 90%. ```shell $ curl -H "Host: canary-demo.com" /version Demo: V2 ``` ## Canary validation succeed, finished the release In the end, you can resume again to finish the rollout process. ```shell vela workflow resume canary-demo ``` Access the gateway endpoint again multi times. You will find out the result always is `Demo: v2`. ```shell $ curl -H "Host: canary-demo.com" /version Demo: V2 ``` ## Canary verification failed, rollback the release 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: You should suspend the workflow before rollback: ```shell $ vela workflow suspend canary-demo Rollout default/canary-demo in cluster suspended. Successfully suspend workflow: canary-demo ``` Then rollback: ```shell $ vela workflow rollback canary-demo Application spec rollback successfully. Application status rollback successfully. Rollout default/canary-demo in cluster rollback. Successfully rollback rolloutApplication outdated revision cleaned up. ``` Access the gateway endpoint again. You can see the result always is `Demo: V1`. ```shell $ curl -H "Host: canary-demo.com" /version 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.