What are canary deployments?

What are canary deployments?

Canary deployments are a form of progressive delivery where a new version of an application is deployed while the old version still exists. First, the change is deployed to a small subset of servers, then is tested and rolled out to the rest of the servers.

How Canary deployments work

  1. In the beginning the current version receives 100% of user traffic
  2. 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
  3. Different types of tests (e.g. smoke tests) can be performed on the new version with no impact to the bulk of the users.
  4. A decision regarding the current canary/subset of traffic takes place in an automated manner
    1. 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%)
    2. 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
  5. 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:

  1. Pausing a deployment and resuming it after a user-defined set of tests have succeeded
  2. Advanced traffic switching methods that take advantage of services meshes available on the Kubernetes cluster
  3. Creation of a preview service that can be used for verifying the new color (i.e smoke testing before the traffic switch takes place)
  4. Inclusion of Anti-affinity rules for better cluster utilization
  5. Easy management of the rollout status via the ArgoCD CLI