Guides
Blue-Green vs Canary on Kubernetes (Simple Walkthrough)
By Ravindra Bagale, DevOps trainer · LinkedIn · Published: · Last updated:
Blue-green keeps two full versions and flips the Service selector; canary runs a small replica share first, then grows or aborts.
Friends, blue-green flips the door; canary opens it a crack. Chala mitrano — keep the old pods warm until you trust the new ones.
मित्रांनो, blue-green दरवाजा पूर्ण उघडते; canary थोडा. Chala mitrano — जुने pods गरम ठेवा.
मित्रों, blue-green दरवाज़ा पूरा खोलता है; canary थोड़ा। Chala mitrano — पुराने pods गरम रखें।
Quick answer
Hold this vertical picture:
- Deploy blue and green.
- Point Service at blue.
- Flip selector or add canary replicas.
- Watch endpoints and errors.
- Finish cutover or roll back.
Language: English · मराठी · हिंदी
Blue-green vs canary
Why two styles
Releases fail; you need a rehearsed escape.
Why: In-place edits hide how to undo.
What: Blue-green = full flip; canary = small percent.
How: Labels + Service selector are the switch.
Example 1: Blue Deployment
Type this:
mkdir -p /tmp/bgc && printf '%s\n' 'apiVersion: apps/v1' 'kind: Deployment' 'metadata: {name: web-blue}' 'spec:' ' replicas: 2' ' selector: {matchLabels: {app: web, color: blue}}' ' template:' ' metadata: {labels: {app: web, color: blue}}' ' spec: {containers: [{name: web, image: public.ecr.aws/docker/library/nginx:1.27-alpine}]}' > /tmp/bgc/blue.yaml && grep color /tmp/bgc/blue.yaml | head -2
You will see:
selector: {matchLabels: {app: web, color: blue}}
What it means: Blue is the live color today.
Example 2: Green Deployment
Type this:
printf '%s\n' 'apiVersion: apps/v1' 'kind: Deployment' 'metadata: {name: web-green}' 'spec:' ' replicas: 2' ' selector: {matchLabels: {app: web, color: green}}' ' template:' ' metadata: {labels: {app: web, color: green}}' ' spec: {containers: [{name: web, image: public.ecr.aws/docker/library/nginx:1.27-alpine}]}' > /tmp/bgc/green.yaml && grep name /tmp/bgc/green.yaml | head -1
You will see:
metadata: {name: web-green}
What it means: Green sits idle until you flip the Service.
Example 3: Service points to blue
Type this:
printf '%s\n' 'apiVersion: v1' 'kind: Service' 'metadata: {name: web}' 'spec:' ' selector: {app: web, color: blue}' ' ports: [{port: 80}]' > /tmp/bgc/svc.yaml && grep color /tmp/bgc/svc.yaml
You will see:
selector: {app: web, color: blue}
What it means: Flip = change selector to green.
Concept 1: Blue-green flip
Change selector; traffic moves together.
Why: Half-updated Services confuse curl tests.
What: patch svc selector to green.
How: Roll back by patching to blue.
Example 4: Blue-green flip command
Type this:
printf '%s\n' 'kubectl patch svc web -p "{\"spec\":{\"selector\":{\"app\":\"web\",\"color\":\"green\"}}"'
You will see:
kubectl patch svc web -p "{"spec":{"selector":{"app":"web","color":"green"}}}"
What it means: All traffic moves in one step — Instant flip.
Example 8: Watch endpoints
Type this:
printf '%s\n' 'kubectl get endpoints web -o wide'
You will see:
kubectl get endpoints web -o wide
What it means: After a flip, endpoints must list the new pods.
Example 9: Rollback blue-green
Type this:
printf '%s\n' 'kubectl patch svc web -p "{\"spec\":{\"selector\":{\"app\":\"web\",\"color\":\"blue\"}}"'
You will see:
kubectl patch svc web -p "{"spec":{"selector":{"app":"web","color":"blue"}}}"
What it means: Flip back — old pods still warm.
Concept 2: Canary ratio
Few new pods share the Service.
Why: Exact percent needs a mesh; replica ratio is fine for labs.
What: stable 9 + canary 1 ≈ 10%.
How: Scale canary to 0 to abort.
Example 5: Canary weight idea
Type this:
printf '%s\n' 'canary: 10 percent pods on new version; 90 percent stay on stable'
You will see:
canary: 10 percent pods on new version; 90 percent stay on stable
What it means: Canary = small blast radius first.
Example 6: Two Deployments one Service (canary labels)
Type this:
printf '%s\n' 'Service selector app=web only; both stable and canary pods share app=web' 'Stable also has track=stable; canary has track=canary'
You will see:
Service selector app=web only; both stable and canary pods share app=web
Stable also has track=stable; canary has track=canary
What it means: Replica counts set the approximate percent.
Example 7: Canary scale math
Type this:
printf '%s\n' 'stable replicas=9; canary replicas=1 → about 10 percent'
You will see:
stable replicas=9; canary replicas=1 → about 10 percent
What it means: Exact percent needs a mesh; replica ratio is the beginner path.
Concept 3: Choose and clean
Capacity and risk decide.
Why: Wrong choice burns money or users.
What: 2× capacity → blue-green; tight → canary.
How: Delete lab YAML when done.
Example 10: Rollback canary
Type this:
printf '%s\n' 'kubectl scale deploy/web-canary --replicas=0'
You will see:
kubectl scale deploy/web-canary --replicas=0
What it means: Remove canary pods; stable keeps 100%.
Example 11: When to pick which
Type this:
printf '%s\n' 'blue-green: need instant rollback and double capacity ok' 'canary: want gradual risk on one cluster capacity'
You will see:
blue-green: need instant rollback and double capacity ok
canary: want gradual risk on one cluster capacity
What it means: Infosys runbooks pick canary when capacity is tight.
Example 12: Cleanup
Type this:
printf '%s\n' 'kubectl delete -f svc.yaml -f blue.yaml -f green.yaml'
You will see:
kubectl delete -f svc.yaml -f blue.yaml -f green.yaml
What it means: Lab cleanup.
Release card
1 Two Deployments 2 Service selector 3 Flip (blue-green) or ratio (canary) 4 Watch endpoints/errors 5 Roll back if needed
Suppose: endpoints empty after flip
Selector labels must match pod labels.
Suppose: canary percent wrong
Adjust replica counts; mesh for exact %.
Ravindra Bagale's Tip
At TCS and Capgemini, interviewers ask cost: blue-green needs roughly 2× pods during the flip; canary needs only a few extra.
TCS आणि Capgemini मध्ये विचारतात: blue-green flip दरम्यान ~2× pods; canary फक्त थोडी extra.
TCS और Capgemini में पूछते हैं: blue-green flip में ~2× pods; canary सिर्फ थोड़ी extra।
Check yourself (quiz)
Q1. Blue-green switch?
Service selector flip
Q2. Canary idea?
Small percent first
Q3. Rollback blue-green?
Point Service back to blue
Q4. Rollback canary?
Scale canary to 0
Q5. Cost of blue-green?
About 2× pods during flip
Q6. Endpoints empty?
Label mismatch
Reading tracking
Mark this guide when you finish. Your browser remembers it on this device.
prepare → flip or canary → measure → finish or roll back.
Did you understand? Let us try it once more.
Frequently asked questions
Blue-green vs rolling update?
Rolling mixes versions in one Deployment; blue-green keeps two and flips.
Exact canary percent?
Service mesh / Ingress weights; replica ratio for labs.
Double cost?
Yes during blue-green overlap.
When canary?
Tight capacity or gradual risk.
Rollback speed?
Blue-green flip is fastest if blue still runs.
Helm?
Same ideas with chart values for colors/weights.