Blue-Green Deployment
Blue-green deployment is a release strategy that runs two identical environments side by side, the live blue version and the new green version, and switches all traffic between them at once. Rollback is as fast as switching traffic back to blue.
How blue-green works
You deploy the new version (green) next to the live one (blue) and validate green fully while it receives no user traffic. When you are confident, you flip a router, in Kubernetes usually a Service selector, so 100% of traffic moves to green. Blue stays available for instant rollback.
payment-api"] S -->|"slot=blue"| B["Blue v3.0.0
live"] S -.->|"after switch"| G["Green v3.1.0
validated"] classDef user fill:#475569,color:#ffffff classDef svc fill:#FFEDD5,color:#1E293B classDef blue fill:#DBEAFE,color:#1E293B classDef green fill:#D1FAE5,color:#1E293B class U user class S svc class B blue class G green
Release workflow
Both Deployments carry app: payment-api plus a slot label. The Service selects one slot.
# 1. Deploy green next to bluekubectl apply -f green-deployment.yamlkubectl rollout status deployment/payment-api-green -n production # 2. Test green directly, with no user traffickubectl port-forward deployment/payment-api-green 8081:8080 -n production &curl -s http://localhost:8081/health # 3. Switch all traffic to greenkubectl patch service payment-api -n production \ -p '{"spec":{"selector":{"app":"payment-api","slot":"green"}}}' # 4. Rollback if needed: point the selector back to bluekubectl patch service payment-api -n production \ -p '{"spec":{"selector":{"app":"payment-api","slot":"blue"}}}'Keep blue running (or scaled down but not deleted) for a rollback window before removing it.
Blue-green vs the alternatives
| Strategy | Traffic shift | Extra capacity |
|---|---|---|
| Rolling update | Gradual pod replacement | Small |
| Canary | Small percentage first | Small |
| Blue-green | All at once | Full second environment |
RememberYou need capacity for two full environments during the release. Check ResourceQuotas and node headroom before starting.
Common MistakeSwitching the Service before every green pod is Ready. Confirm
kubectl rollout statusreports success first, otherwise users hit pods that are still starting.
TipSchedule payment-style releases off-peak, so the doubled footprint does not compete with live traffic for capacity.
Frequently Asked Questions
What is the real cost of blue-green compared with canary?
Blue-green runs two production-sized environments at once, which roughly doubles compute for the validation and rollback window. A canary needs capacity only for a small slice of traffic, but it takes longer to build confidence.
Why is the database the hard part of blue-green?
Both versions usually share one database, so a schema change must be backward compatible with blue while green is live. A breaking migration removes the instant rollback, because switching back leaves blue talking to a schema it does not understand.
How is blue-green different from a rolling update?
A rolling update mixes old and new pods in the same live pool while it progresses. Blue-green keeps the versions separate and moves all traffic in a single step after validation.