zenkubernetes
Learning pathLessonsPractice studioGet the pack
Open practice studio ↗
Foundations
What is Kubernetes?
Setting up for k8s development
The Main Pillars of Kubernetes
Workload types
Creating our first cluster
Core Concepts
Deploying applications
Declaring services
Set up external access
ConfigMaps & Secrets
Debugging & Troubleshooting
Liveness & Readiness Probes
Scaling applications
Updating applications
Revision histories and rollbacks
Application projectPRO
Your application deployment projectBuild and containerize your applicationPackage and deploy with HelmVerify your deployment and hand it over
Troubleshooting practicePRO
Lab: the release that never startsLab: healthy Pods, unreachable applicationLab: configuration blocks startupLab: running does not mean readyLab: recover a failed release
Back at workPRO
Your workplace field guide
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.28

Now 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 back

This 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-nginx

We 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.

Previous← Updating applicationsNextYour application deployment project →
zen-cluster · simulated kubectl
Welcome to your zen cluster. Try: kubectl get pods
$
Try: kubectl get pods, kubectl get deployments, help