CKAD · 19 November 2026 · 4 min read
Blue/green deployments in Kubernetes, step by step
Run the new version beside the old one, test it, then switch a Service's selector to send all traffic across, and switch back if anything is wrong. With YAML, the kubectl commands and how it differs from a canary.
A blue/green deployment in Kubernetes runs two complete versions of an application side by side, as two Deployments, and puts one Service in front of them. The Service's label selector decides which version gets the traffic. You test the new version (green) while users stay on the old one (blue), then change the selector to send everyone to green in one step. If green misbehaves, you change the selector back and everyone is on blue again within seconds.
TL;DR
- Two Deployments with a shared
applabel and a differentversionlabel:version: blueandversion: green. - One Service whose selector includes the version:
app: shop, version: blue. - Test green directly (a second Service, or
kubectl port-forward) before any user reaches it. - Switch:
kubectl patch service shop -p '{"spec":{"selector":{"app":"shop","version":"green"}}}'. - Roll back: patch the selector back to
blue. Delete blue only once green has proved itself. - Exam: Application Deployment, 20% of the CKAD.
The whole pattern in one picture

Want to change it for your own app? Open this diagram in archhy, our sister product for architecture diagrams, and press Make a copy in archhy: it opens as your own copy, ready to edit. Add an Ingress, a canary, or your own names.
Why not just a rolling update?
A Deployment's default rolling update replaces Pods a few at a time (by default up to 25% extra and 25% unavailable). It is simple and needs no extra capacity, but while it runs, some users get the old version and some the new, and if the new version is broken, the way back is another rolling update. Blue/green trades double the capacity during a release for two things: green is tested before anyone uses it, and both the switch and the rollback are instant.
Step 1: the blue version
Blue is what users run today. Its Pods carry both labels:
apiVersion: apps/v1kind: Deploymentmetadata: name: shop-bluespec: replicas: 3 selector: matchLabels: app: shop version: blue template: metadata: labels: app: shop version: blue spec: containers: - name: web image: nginx:1.26 ports: - containerPort: 80And the Service that users reach selects blue:
apiVersion: v1kind: Servicemetadata: name: shopspec: selector: app: shop version: blue ports: - port: 80 targetPort: 80kubectl apply -f blue.yaml -f service.yamlkubectl get endpointslices -l kubernetes.io/service-name=shopStep 2: deploy green beside it
Green is the same Deployment with a new name, a new image and version: green. Users see nothing yet: the Service still selects blue.
sed -e 's/shop-blue/shop-green/' -e 's/version: blue/version: green/' -e 's/nginx:1.26/nginx:1.27/' blue.yaml > green.yamlkubectl apply -f green.yamlkubectl rollout status deployment/shop-greenStep 3: test green before anyone uses it
Reach green without touching the Service users depend on. For a quick check, forward a local port to it:
kubectl port-forward deployment/shop-green 8080:80curl -s localhost:8080 | headFor a longer test, add a second Service, shop-green, that selects version: green, and point your tests or a test Ingress host at it.
Step 4: switch, and switch back
When green is good, change the user-facing Service's selector. Every new connection goes to green straight away:
kubectl patch service shop -p '{"spec":{"selector":{"app":"shop","version":"green"}}}'kubectl get endpointslices -l kubernetes.io/service-name=shop -o wideIf something is wrong, the rollback is the same command with blue. Keep blue running until you are sure, then scale it to zero or delete it:
kubectl scale deployment shop-blue --replicas=0Next release, green is the live version and the new one becomes blue (or you keep the colors fixed and swap images); either way the pattern repeats.
Blue/green vs canary
- Blue/green moves all traffic at once, after testing. The selector includes the version label.
- Canary moves a share of traffic first. The Service selects only the shared
applabel, and the ratio of replicas sets the share: four stable Pods and one canary Pod send about one request in five to the canary. Our CKAD practice questions include one.
Things that catch people out
- A Deployment's selector cannot change after it is created. Get
versioninto both the selector and the template labels from the start. - Long-lived connections (WebSockets, keep-alive) stay on the old Pods after the switch until they reconnect.
- Database changes must work with both versions while both run: add columns before you use them, remove them after.
- Double capacity: during a release, both versions run in full. On a small cluster, check you have room (
kubectl describe nodes, Allocatable).
The blue/green series
- Blue/green with a Service selector (this article): the pattern, and the version the exam asks for.
- Blue/green with an Ingress: switch the backend at the edge; weights with Traefik.
- Blue/green with the Gateway API: standard weights in an HTTPRoute, and a header to test green.
- Blue/green with Istio: subsets, weights, mirroring live traffic to green.
Draw your own
The diagram above was drawn in archhy, our sister product, with its Kubernetes icon pack. Open it in archhy and make a copy to make it your own, or start a fresh one from Draw a Kubernetes architecture diagram. The idea of blue/green releases comes from archhy’s own article, which draws the pattern on Amazon ECS.
Keep going
Practice rolling updates, rollbacks, blue/green and canary releases on a real cluster in the CKAD course's Rollouts and release strategies module, and see how the exam treats them in How the CKAD exam works.