How to roll back a Kubernetes deployment
Watch a rollout, undo a bad one with kubectl rollout undo, go back to a chosen revision, and set the deployment so a broken version never takes all the traffic.
Checked 2026-11-19Changing a Deployment's pod template (most often the image) starts a rollout: Kubernetes creates a new ReplicaSet and moves pods to it a few at a time. The old ReplicaSet is kept, scaled to zero, which is what makes a rollback quick.
Watch it
kubectl set image deployment/web web=registry.example/web:1.4
kubectl rollout status deployment/web # waits; non-zero exit if it fails
kubectl get pods -l app=web # look for ImagePullBackOff or CrashLoopBackOff
Undo the last change
kubectl rollout undo deployment/web
That goes back to the previous revision. It is a new rollout of the old pod template, so it takes the same careful steps.
Go back to a chosen revision
kubectl rollout history deployment/web
kubectl rollout history deployment/web --revision=3 # what was in it
kubectl rollout undo deployment/web --to-revision=3
The CHANGE-CAUSE column is empty unless you set the kubernetes.io/change-cause annotation when you change the deployment:
kubectl annotate deployment/web kubernetes.io/change-cause="web 1.4: new checkout"
How many old revisions are kept is spec.revisionHistoryLimit (10 by default).
Make a bad version stop by itself
A rollback is the cure; these settings are the prevention:
spec:
strategy:
rollingUpdate:
maxUnavailable: 0 # never fewer working pods than asked for
maxSurge: 1 # one new pod at a time
minReadySeconds: 10
progressDeadlineSeconds: 120
template:
spec:
containers:
- name: web
readinessProbe:
httpGet: { path: /healthz, port: 8080 }
With a readiness probe, a new pod that never becomes ready never gets traffic, and with maxUnavailable: 0 the old pods keep running. The rollout stalls and is marked failed after progressDeadlineSeconds; Kubernetes does not roll back on its own, so the undo above is still your move.
Pause and resume
kubectl rollout pause deployment/web # make several changes, one rollout
kubectl rollout resume deployment/web