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
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
| Situation | What to do / command | Trap |
|---|---|---|
| Switch from blue to green | Create 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 switch | kubectl get endpoints web or kubectl describe svc web | Do not judge by the Deployment alone. Check the pod addresses the Service actually picked |
| Send only ~20% of requests to the new version | Match replica counts, e.g. 4 existing + 1 canary, and give both the selector labels | If version stays in the selector, canary pods get no requests |
| Roll back the canary | kubectl scale deployment <canary> --replicas=0 | No need to edit or roll back the existing Deployment |
| Go back to the previous version within one Deployment | kubectl 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
Further reading: CNCF certification curriculum · Deployments · Service · Zero-Downtime Deploys (Rolling Update) · Service Mesh ② Splitting Traffic