How Canary deployments work
- In the beginning the current version receives 100% of user traffic
- A new deployment, the “canary” is performed with brand new pods and only a small amount of traffic (e.g. 5%) is sent to it
- Different types of tests (e.g. smoke tests) can be performed on the new version with no impact to the bulk of the users.
- A decision regarding the current canary/subset of traffic takes place in an automated manner
- If the new version works as expected, a larger portion of live traffic is sent to the new version and the process repeats again for different percentages of canary traffic (e.g. 5%, 25%, 50%, 75%, 100%)
- If the new version has issues at any point in the canary traffic, the Kubernetes service is switched back to the original version. This has minimal impact on most users. The canary version is destroyed and everything is back to the original state
- At the end, 100% of traffic goes to the new version and the old version can be discarded.
Canary deployments With Codefresh
By default Kubernetes offers two very simple deployment methods (rolling updates and destroy/create) that can easily result in unplanned downtime if the new version of an application does not work as expected.
Codefresh offers a canary plugin that can be used in place of a standard Kubernetes deployment. The plugin offers the basic canary deployment process along with the gradual switch of live traffic to a subset of live pods with the new version.
Users of the plugin can configure the percentage of pods to switch to the new version for each canary wave as well as the time period to wait before the next increase. The plugin checks pod restart numbers to decide if the canary version is healthy or not.
The plugin is open-source code, and can be used in Codefresh in a declarative manner or even manually from any container image.
Advanced progressive delivery with Argo Rollouts
In addition to the basic canary plugin, Codefresh offers also advanced progressive delivery methods by leveraging Argo Rollouts, a project specifically designed for gradual deployments to Kubernetes.
Through Argo Rollouts, Codefresh can perform advanced canary deployments that support:
- Pausing a deployment and resuming it after a user-defined set of tests have succeeded
- Advanced traffic switching methods that take advantage of services meshes available on the Kubernetes cluster
- Creation of a preview service that can be used for verifying the new color (i.e smoke testing before the traffic switch takes place)
- Inclusion of Anti-affinity rules for better cluster utilization
- Easy management of the rollout status via the ArgoCD CLI