Lesson 14
Revision histories and rollbacks
~3 min read
In Kubernetes, if you want to revert a rollout that happened some versions ago, you can do so using the rollback feature. This feature allows you to revert back to a previous version of your Deployment.
To perform the rollback, you would first need to identify the revision number of the Deployment that you wish to roll back to. This can be done by using the kubectl rollout history command, which will display a list of all past revisions of the Deployment.
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.