Kubernetes Rolling Updates and Rollbacks
Fast recall
Quick revision
Core answer
maxSurge (extra pods above desired) and maxUnavailable (pods allowed offline). maxSurge: 1, maxUnavailable: 0 guarantees zero downtime. Kubernetes retains old ReplicaSets (up to revisionHistoryLimit, default 10) so kubectl rollout undo is instant and requires no image rebuild. For higher-risk changes, blue-green and canary are safer alternatives to native rolling.Understanding of how Kubernetes achieves zero-downtime deployments
Omitting `maxUnavailable: 0` (allows pods terminated before replacements ready) or missing readiness probes (bad pods receive traffic)
Explain that Kubernetes keeps the previous ReplicaSet for rollback, discuss `revisionHistoryLimit`, mention PodDisruptionBudget during node drains, and compare rolling to blue-green and canary for risk reduction
Interview-ready guide
Interview answer
Kubernetes rolling updates replace running Pods incrementally — new Pods start before old Pods terminate, maintaining availability throughout the deployment. The two parameters that control update speed and risk are maxSurge and maxUnavailable.
Rolling update mechanics
maxSurge: 1allows one pod above the desired replica count during rollout — with 3 replicas, Kubernetes starts one new Pod (4 total), waits for it to pass readiness, terminates one old Pod; this continues until all pods run the new version.maxUnavailable: 0ensures zero pod downtime — no old pod terminates until its replacement passes readiness; set this to 0 in production for services that cannot tolerate reduced capacity during deploys.- The readiness probe is the critical coupling: a broken new version where readiness never passes stalls the rollout — old pods keep serving, the broken new pod sits in
0/1 Running, and the rollout never progresses; this is a feature, not a bug.
Triggering and monitoring
kubectl set image deployment/payment-service app=payment-service:v2.1.0triggers a rolling update — Kubernetes records this as a new revision in the rollout history.kubectl rollout status deployment/payment-serviceblocks and streams progress until all replicas are on the new version orprogressDeadlineSeconds(default 600s) elapses.kubectl rollout history deployment/payment-serviceshows revision history; annotatekubernetes.io/change-causeon updates so the history is meaningful.
Rollback
kubectl rollout undo deployment/payment-servicereverts to the previous ReplicaSet immediately — old pods are recreated from the previous spec; no image rebuild required.kubectl rollout undo deployment/payment-service --to-revision=3rolls back to a specific revision — useful when the last version is also broken.revisionHistoryLimit(default 10) controls how many old ReplicaSets are kept; setting it too low means you cannot roll back past recent releases.
When rolling is not enough
- For breaking database schema changes, use blue-green — deploy v2 as a separate Deployment, verify in isolation, flip the Service selector atomically to switch traffic, flip back for rollback.
- For high-risk large changes, use canary — deploy one or two pods alongside the stable version, weight 10% of traffic to them via Ingress or service mesh, monitor error rate, progressively shift to 100%.
- Always pair rolling with a PodDisruptionBudget —
minAvailable: 2prevents node drains from evicting all replicas simultaneously during cluster maintenance.
Kubernetes Rolling Updates and Rollbacks
Direct Answer
Rolling updates replace pods incrementally — new pods start, pass readiness, then old pods are terminated. Behavior is controlled by maxSurge (extra pods above desired) and maxUnavailable (pods allowed offline). maxSurge: 1, maxUnavailable: 0 guarantees zero downtime. Kubernetes retains old ReplicaSets (up to revisionHistoryLimit, default 10) so kubectl rollout undo is instant and requires no image rebuild. For higher-risk changes, blue-green and canary are safer alternatives to native rolling.
Common Mistakes & Pitfalls
Omitting maxUnavailable: 0 (allows pods terminated before replacements ready) or missing readiness probes (bad pods receive traffic)
Check your understanding
Answer these without looking back at the article.
- How does a canary deployment differ from a rolling update?
- What happens if all pods in a rolling update fail their readiness probe?
- How do you pause and resume a rolling update in Kubernetes?
- What is Argo Rollouts and when would you add it instead of native rolling?
Related interview prep categories
2Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.