Lesson 14
Revision histories and rollbacks
~3 min read
A Deployment rollback restores a previous Pod template, including its container images and configuration references. Before rolling back at work, check that the older application version is compatible with the current database and external configuration.
Use kubectl rollout history to list the retained revisions and identify the one you want to restore:
kubectl rollout history deployment nginx-deployment
REVISION CHANGE-CAUSE
1 <none>
2 version change to 1.27
3 version change to 1.28Now you see why it was a good idea to annotate our updates. If we hadn't annotated, all the causes would have been <none>.
Once we have identified the desired revision number we want to roll back to, you can use the kubectl rollout undo command followed by the Deployment name and the revision number to revert the Deployment to.
For instance, if we wanted to revert back to a revision before we started updating, and that revision was number 1, you would use the following command:
kubectl rollout undo deployment nginx-deployment --to-revision=1
deployment.apps/nginx-deployment rolled backThis will revert your Deployment back to the state it was in at revision 1, effectively undoing the changes made in the subsequent rollouts. We see now that the deployment also has the original image version when we query the deployments.
kubectl get deployments -o wide
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
nginx-deployment 1/1 1 1 22m nginx nginx:1.26.2 app.kubernetes.io/name=my-nginxWe covered most of the basic concepts of Kubernetes and now it is time to put some of this together and set up a real application in Kubernetes as a Capstone project.