Skip to main content

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.
flowchart TD A["3 pods on v1"] --> B["Create new v2 pod
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

YAML
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: 3

With 10 replicas, maxSurge: 2 and maxUnavailable: 0, the count stays between 10 and 12.

Operate a rollout

Bash
kubectl set image deployment/payment-api payment-api=registry.example.com/payment-api:v3.2.0 -n production
kubectl rollout status deployment/payment-api -n production
kubectl rollout pause deployment/payment-api -n production # inspect partial rollout
kubectl rollout resume deployment/payment-api -n production
kubectl rollout undo deployment/payment-api -n production
kubectl rollout restart deployment/payment-api -n production # after ConfigMap changes

Stuck rollout checklist

  • Run kubectl get pods and look for new pods at 0/1 Ready.
  • Run kubectl describe pod on the new pod and read probe failures.
  • Read kubectl logs for startup errors.
  • If the release is bad, run kubectl rollout undo.
Remember

The readiness probe is the safety mechanism. Without a meaningful one, traffic reaches pods before they can serve it.

Security

During 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 Mistake

Non-zero maxUnavailable on 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.

Found a mistake, an outdated step or a broken link?