Blue-Green and Canary deployments are not supported by default in K8s. We need to implement them manually.
In blue-green deployments, while the old version (blue) is still running, we bring up the new version (green) and switch the users from blue to green all at once.
To implement blue-green deployment in k8s, we deploy both blue and green version as Deployment. The blue deployment has all the pods labelled as version: v1
whereas green deployment has all the pods labelled as version: v2
. When we want to shift to the green deployment, we just update the service to route to pods with label version: v2
.
To implement canary deployment, create a new Deployment (canary deployment) with label version: v2
containing just 1 pod. Also, have a common label between the old and new deployments and use that label in the service to direct traffic to both the deployments. Since the canary deployment only has 1 pod, it will only serve a portion of the traffic. Once we are sure that the canary deployment is working fine, we can scale up the canary deployment to bring up the desired number of pods and delete the primary deployment.