Rolling Updates & Rollbacks

Deployments replace Pods gradually during updates and let you roll back instantly if something breaks.

When you change a Deployment's image, Kubernetes performs a rolling update: it brings up new Pods and tears down old ones a few at a time, so your app never fully goes down.

Controlling the rollout

Two settings under strategy.rollingUpdate tune the pace:

  • maxUnavailable — how many Pods may be down during the update.
  • maxSurge — how many extra Pods may be created above the desired count.

Rolling back

Every rollout is recorded in a history. If a new version misbehaves, kubectl rollout undo returns to the previous ReplicaSet almost instantly.

kubectl rollout status deployment/web
kubectl rollout undo deployment/web

Example

Example · bash
# Trigger a rolling update by changing the image
kubectl set image deployment/web nginx=nginx:1.27.1

# Watch the rollout progress
kubectl rollout status deployment/web

# See past revisions
kubectl rollout history deployment/web

# Roll back to the previous version
kubectl rollout undo deployment/web

When to use it

  • A production service uses RollingUpdate strategy so that new pods replace old ones gradually, keeping at least 2 pods serving traffic at all times.
  • A team sets maxSurge=2 to speed up a release by allowing two extra pods during the rollout instead of replacing one at a time.
  • An SRE pauses a rolling update after 30% of pods are updated to monitor error rates before proceeding with the rest.

More examples

Rolling update strategy in Deployment

Configures rolling update so at most 1 pod is unavailable and at most 1 extra pod runs at any time during the update.

Example · yaml
spec:
  replicas: 4
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
      maxSurge: 1

Trigger and monitor a rollout

Triggers a rolling update by changing the image and monitors the rollout until all pods are updated and ready.

Example · bash
kubectl set image deployment/web web=myapp:3.0
kubectl rollout status deployment/web
# Waiting for deployment web rollout to finish...
# deployment web successfully rolled out

Pause, inspect, and resume

Pauses the rollout mid-update for canary validation, then resumes it once the new pods are confirmed healthy.

Example · bash
kubectl rollout pause deployment/web
# Check error rate on the partially-updated pods...
kubectl get pods -l app=web

# Resume if healthy
kubectl rollout resume deployment/web

Discussion

  • Be the first to comment on this lesson.