Rolling Update
A rolling update is the default Kubernetes Deployment strategy that replaces old pods with new ones gradually, so enough pods keep serving traffic throughout the release. It enables zero-downtime deployments when readiness probes and surge settings are configured correctly.
How it proceeds
The Deployment creates new pods, waits for them to pass their readiness probe, then terminates old pods, repeating until all are updated. Two settings control the pace:
- maxSurge: how many pods above the desired count may exist during the update.
- maxUnavailable: how many pods below the desired count may be unavailable.
maxSurge 1"] B -->|"readiness passes"| C["Terminate one v1 pod"] C --> D{"All pods on v2?"} D -->|"No"| B D -->|"Yes"| E["Update complete"] classDef step fill:#DBEAFE,color:#1E293B classDef decide fill:#475569,color:#ffffff classDef done fill:#D1FAE5,color:#1E293B class A,B,C step class D decide class E done
Configure
spec: replicas: 6 strategy: type: RollingUpdate rollingUpdate: maxSurge: 2 maxUnavailable: 0 # keep full capacity during the release template: spec: containers: - name: payment-api image: registry.example.com/payment-api:v3.1.0 readinessProbe: httpGet: { path: /health, port: 8080 } periodSeconds: 5 failureThreshold: 3With 10 replicas, maxSurge: 2 and maxUnavailable: 0, the count stays between 10 and 12.
Operate a rollout
kubectl set image deployment/payment-api payment-api=registry.example.com/payment-api:v3.2.0 -n productionkubectl rollout status deployment/payment-api -n productionkubectl rollout pause deployment/payment-api -n production # inspect partial rolloutkubectl rollout resume deployment/payment-api -n productionkubectl rollout undo deployment/payment-api -n productionkubectl rollout restart deployment/payment-api -n production # after ConfigMap changesStuck rollout checklist
- Run
kubectl get podsand look for new pods at 0/1 Ready. - Run
kubectl describe podon the new pod and read probe failures. - Read
kubectl logsfor startup errors. - If the release is bad, run
kubectl rollout undo.
RememberThe readiness probe is the safety mechanism. Without a meaningful one, traffic reaches pods before they can serve it.
SecurityDuring a rolling update, old and new versions run at the same time. Database schema and message formats must be backward compatible, or the mixed fleet can corrupt data.
Common MistakeNon-zero
maxUnavailableon services with no spare capacity, which reduces capacity at the start of each release.
Frequently Asked Questions
How does a rolling update avoid downtime?
maxSurge and maxUnavailable bound how many pods change at once, and readiness probes ensure traffic goes only to pods that can serve. Old pods are removed only after replacements are ready.
Why can a zero-downtime update still drop requests?
Often a missing readiness probe, or an app that does not handle SIGTERM and drain in-flight requests before the pod exits. Add a preStop delay and graceful shutdown.
How do I trigger a restart without changing the image?
Run kubectl rollout restart. It changes the pod template annotation and performs a normal rolling update.