Rollback
- Docker & Kubernetes course
- Intermediate
- Lesson 29/82
- 4 min
Learn to undo with kubectl rollout undo.
Rollback
A Deployment keeps old ReplicaSets (10 by default, revisionHistoryLimit); thanks to this, rolling back takes seconds. The history is seen with rollout history:
$ kubectl rollout history deployment/web
REVISION CHANGE-CAUSE
1 <none>
2 nginx 1.27.3
3 nginx 1.28 deneme
$ kubectl rollout undo deployment/web # to the previous version
$ kubectl rollout undo deployment/web --to-revision=1 # to a specific versionPausing and resuming
To make several changes (image, resources, environment variables) in a single rollout, the deployment is paused; changes accumulate and are applied at once when resumed. To redo a rollout from the start, restart is used (e.g. when a ConfigMap changed):
kubectl rollout pause deployment/web
kubectl set image deployment/web nginx=nginx:1.27.3
kubectl set resources deployment/web -c nginx --limits=memory=256Mi
kubectl rollout resume deployment/web
kubectl rollout restart deployment/webPractice Roll back a bad version
Write three commands: show the rollout history of the web deployment; roll back to revision 2; wait for the rollout to finish.
Starter code
# buraya yazSample solution
kubectl rollout history deployment/web
kubectl rollout undo deployment/web --to-revision=2
kubectl rollout status deployment/webExpected output
REVISION CHANGE-CAUSE 1 <none> 2 nginx 1.27.3 3 nginx 1.28 deneme deployment.apps/web rolled back deployment "web" successfully rolled out
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What happens in the history after kubectl rollout undo deployment/web?
- The last revision is deleted and the number goes back
- The history is cleared
- Nothing changes
- The previous version's template comes back with a new revision number Correct answer
Explanation: A rollback is also a rollout.
2 Go back to a specific revision.
kubectl rollout undo deployment/web ____=1
kubectl rollout undo deployment/web --to-revision=1
Explanation: --to-revision takes the number from the history.
3 Match.
| Term | Meaning |
|---|---|
rollout history |
Revision history |
rollout undo |
Roll back |
rollout pause/resume |
Batch changes |
rollout restart |
Recreate the pods |