Deployment Strategies
Deployment is the riskiest step in the pipeline. Compare rolling, blue-green and canary strategies, use feature flags to decouple release from deploy, and design for zero downtime with fast, safe rollback.
What is this?
A deployment strategy is how a new version replaces the old one in production. Rolling updates swap instances gradually; blue-green runs two full stacks and switches traffic in one jump; canary routes a small percentage of users to the new version first. Feature flags separate code release from user visibility, enabling deploy-then-enable workflows and instant toggles.
Why do you need it?
- Zero-downtime deployment keeps users served while a new version takes over.
- Gradual strategies limit blast radius — a bad release affects few users, not everyone.
- Blue-green and canary give a clean, instant rollback path because the old version stays ready.
- Feature flags let teams deploy code safely behind a switch and turn features on progressively.
- The right strategy converts deployment from an incident into an observable, reversible event.
Mental model
Changing tyres on a moving car
Zero-downtime deployment
You cannot stop the car (the service) and swap all four wheels at once. Instead you change one wheel at a time (rolling) or keep a second car running alongside and let passengers move over once it is proven (blue-green).
How it works
- A rolling update creates new replicas and terminates old ones a few at a time while the load balancer keeps serving.
- Blue-green deploys the new version as a complete 'green' stack beside the 'blue' one, then flips the router in one switch.
- Canary routing sends a small share of traffic (5-10%) to the new version and watches error rates before ramping up.
- Feature flags gate behavior behind a runtime toggle, so a release ships without exposing anything until the flag is on.
- Rollback is strategy-specific: rolling reverses the update, blue-green flips back to blue, canary redirects 100% to the old version.
A canary rollout ramping from 10% to 100% before the old version is removed.
Key commands
kubectl set image deployment/web web=myapp:1.5.0Trigger a rolling update of the web deployment.
kubectl rollout status deployment/webWatch the rollout until it completes or pauses.
kubectl rollout undo deployment/webRoll back to the previous revision.
kubectl get pods -wWatch pods being created and terminated during a rollout.
curl -s http://localhost:8080/healthzCheck the health endpoint before directing traffic to a new version.
Examples
A rolling update with health-gated rollout on Kubernetes
apiVersion: apps/v1kind: Deploymentmetadata: name: webspec: replicas: 5 strategy: type: RollingUpdate rollingUpdate: maxUnavailable: 1 maxSurge: 1 selector: matchLabels: app: web template: metadata: labels: app: web spec: containers: - name: web image: myapp:1.4.0 ports: - containerPort: 8080Kubernetes rolls out the new image one pod at a time: at most one pod may be down (maxUnavailable) and one extra may be created (maxSurge). A new pod only counts once its readiness probe passes, so the rollout pauses automatically if the new version cannot serve.
In production
- Rolling updates are the default for most stateless services because they are simple and require no extra capacity.
- Blue-green is chosen for database schema migrations where old and new versions must coexist briefly.
- Canary deploys give metric-based confidence for high-traffic, high-risk changes.
- Feature flags let product teams release code on Tuesday and enable it on Friday without a deploy.
- Incident playbooks pin down the rollback command for each strategy so reverting is one step.
Best practices
- Always define health checks and readiness probes so the orchestrator can gate the rollout.
- Keep old capacity around until the new version is verified — blue-green relies on it.
- Watch error rate, latency and saturation, not just availability, during a canary.
- Make feature flags short-lived and remove them after the code path is proven.
- Automate rollback and test it periodically so it works when you need it.
Common mistakes
- Rolling out without health checks, so unhealthy pods get traffic and users see errors.
- Blue-green sharing the same database, so the 'old' version cannot actually serve a rollback.
- Canary with no metrics threshold — traffic ramps to 100% regardless of the new version's error rate.
- Leaving feature flags in the code forever, accumulating untested dead paths.
Common issues
Rollout stuck or unavailable replicasThe new version fails its readiness probe, so the orchestrator refuses to add it.
Read kubectl describe deployment for events, fix the app or probe, and restart the rollout.
Users see errors during a rolling updatePods are terminated before they drain in-flight requests, or probes are too lenient.
Configure a graceful shutdown (SIGTERM handling) and a proper readiness gate before traffic moves on.
Blue-green rollback still hits the bad versionThe blue and green stacks share state (same DB, cache) that the new version corrupted.
Ensure old and new versions are isolated or upgrade state schema in a compatible, reversible way.
Debugging tips
- Watch the rollout progress with kubectl rollout status and describe to see why it paused.
- In a canary, compare error rates between the stable and canary pods using the same trace IDs.
- Verify the old version is truly still healthy before using it as a rollback target.
- Check readiness probe failures in events — they are usually why a rollout stalls.
Interview checkpoint
Hands-on lab
- Build two versions of the same application
- Run the old version and verify it serves traffic
- Deploy the new version as a parallel 'green' stack
- Switch traffic and verify, then roll back
Model a Blue-Green Switch with Docker
30 min · intermediate
Quick quiz
Which strategy requires running two complete, parallel stacks of the application?
A canary deployment sends 100% of traffic to the new version from the start.
What is the main advantage of a feature flag compared with a deployment?
Cheat sheet
rollingGradual replica swap, needs no extra capacityblue-greenTwo full stacks, instant switch + rollbackcanarySmall % traffic, ramp on metricsrecreateStop all, start all — downtime, rarely usedkubectl set image deployment/web web=myapp:1.5.0Trigger a rolloutkubectl rollout status deployment/webWatch progresskubectl rollout undo deployment/webRoll back a revisionkubectl get pods -wWatch pod churncurl -s http://localhost:8080/healthzVerify health before cutover