patternbashkubernetesTip
kubectl rollout undo: instant rollback to previous deployment revision
Viewed 0 times
rollout undorollbackrevision historyreplicasetkubectl rolloutdeployment historyrevisionhistorylimitkubectl set image
Problem
A deployment just went out and is causing errors. You need to roll back immediately to the previous working version.
Solution
Use
kubectl rollout undo to revert to the previous revision instantly.# Roll back to the previous revision
kubectl rollout undo deployment/myapp
# Roll back to a specific revision
kubectl rollout history deployment/myapp # list revisions
kubectl rollout undo deployment/myapp --to-revision=3
# Monitor the rollback
kubectl rollout status deployment/myapp
# Check current image after rollback
kubectl get deployment myapp \
-o jsonpath='{.spec.template.spec.containers[0].image}'Why
Kubernetes Deployments maintain a revision history (configurable via revisionHistoryLimit). Each update creates a new ReplicaSet. Rolling back replaces the active ReplicaSet with a previous one, which Kubernetes treats as another rolling update.
Gotchas
- revisionHistoryLimit defaults to 10 — if you need further history, increase this value in the Deployment spec
- rollout undo only undoes the pod template (image, env vars) — ConfigMap and Secret changes are not reverted
- If you used
kubectl set imageto deploy, the revision is tracked; if you edited the manifest and applied, same thing - After
rollout undo, the revision that was undone becomes the new latest revision — history is re-ordered - Add
--record(deprecated in 1.25) or use annotations to track what change each revision contains
Context
Recovering quickly from a bad deployment
Revisions (0)
No revisions yet.