Skip to main content
Running workloadsLesson 4 of 14

Blue/green and canary with core primitives (CKAD)

This relates to "Use Kubernetes primitives to implement common deployment strategies (e.g. blue/green or canary)" in the CKAD Application Deployment (20%) domain. Without extra tools such as a service mesh, we follow two ways to move web 1.0 to 2.0 using only Deployments, Services and labels.

The default way a single Deployment replaces pods one by one is in Zero-Downtime Deploys (Rolling Update), and splitting ratios with a mesh regardless of pod count is in Service Mesh ② Splitting Traffic.

Requests to blue100%
Requests to green-
Pods (blue · green)3 · 0
Blue · current versionGreen · new versionUserrequestsweb Servicepicks by selectorOperatorkubectlBlue podsweb:1.03 podsweb-blueDeploymentGreen podsweb:2.0web-greenDeploymentrequestversion=blue
RequestAppears in a later step

What you will learn

  • How to switch blue/green with one Service selector
  • Why keeping blue makes rollback a one-line selector change
  • How replica counts become the canary ratio, and the limits
  • Mesh-less canary vs. mesh ratio splitting

Common exam questions​

SituationWhat to do / commandTrap
Switch from blue to greenCreate the green Deployment → change the selector version with kubectl edit svc web (or kubectl patch)Green pod labels must match the new selector exactly. If not, endpoints are empty and requests fail
Verify the switchkubectl get endpoints web or kubectl describe svc webDo not judge by the Deployment alone. Check the pod addresses the Service actually picked
Send only ~20% of requests to the new versionMatch replica counts, e.g. 4 existing + 1 canary, and give both the selector labelsIf version stays in the selector, canary pods get no requests
Roll back the canarykubectl scale deployment <canary> --replicas=0No need to edit or roll back the existing Deployment
Go back to the previous version within one Deploymentkubectl rollout undo deployment <name>This is a rolling-update rollback. It differs from blue/green or canary rollback

Try it yourself​

kubectl get pods -L version # Pod count per version
kubectl get svc web -o jsonpath='{.spec.selector}' # Which pods the Service picks
kubectl get endpointslices -l kubernetes.io/service-name=web # Pods that actually get requests
kubectl get deploy -l app=web # Replicas of blue and green
kubectl port-forward deploy/web-green 8080:<port> # Test green before switching

Check yourself

  1. You changed the web Service selector from version: blue to version: green, and now every request fails. What should you check first?
  2. For a mesh-less canary, you run web-blue with 3 replicas and web-green with 1, but the canary gets no requests. What is the likely cause?
  3. At the canary stage (blue 3, green 1), errors rise. What is the simplest rollback?

Further reading: CNCF certification curriculum · Deployments · Service · Zero-Downtime Deploys (Rolling Update) · Service Mesh ② Splitting Traffic