In this article, we will see how to rollback deployment in Kubernetes Using 4 Easy Steps. In a prod environment, sometimes it does happen that you do a specific deployment in your Kubernetes cluster and even after doing all the testing in lower environments, it fails due to certain reasons resulting in downtime of your applications. This can sometimes also cause a major outage for some of the critical applications and can lead to a huge financial loss.
So to deal with a problem like this, whenever a deployment fails in Kubernetes, instead of fixing the issue you would like to quickly rollback to previous working revision so that atleast application comes back to the running state. This can be easily done by following few simple steps explained in the below section.
How to Rollback Deployment in Kubernetes Using 4 Easy Steps
Also Read: How to Solve Kubernetes Pod CreateContainerConfigError
Step 1: Prerequisites
a) You should have access to the namespace of the Application Kubernetes Cluster.
b) You should have
kubectl utility available in your System.
c) You should have access to perform the deployment in Application namespace.
Step 2: Check Revisions
In the first step, you need to check all the latest revisions of the deployment available to rolled back to using
kubectl -n <namespace> rollout history deployment <deploy_name> syntax. For example, in our case we have namespace
rtl02 where we need to rollback our deployment
app-fscm. So before doing that, we need to check all the latest available revisions by using
kubectl -n rtl02 rollout history deployment app-fscm command as shown below.
[cyberithub@node1]$ kubectl -n rtl02 rollout history deployment app-fscm REVISION CHANGE-CAUSE 45 ... 46 ... 47 ... 48 ... 49 ...
Step 3: Rollback Deployment
If you want to rollback the deployment to previous version then you need to run
kubectl rollout undo deployment app-fscm command as shown below.
[cyberithub@node1]$ kubectl rollout undo deployment app-fscm
If you would like to rollback the deployment to a specific revision let's say to
revision 47 as in our case then you need to run
kubectl rollout undo deployment app-fscm --to-revision=47 command as shown below.
[cyberithub@node1]$ kubectl rollout undo deployment app-fscm --to-revision=47
It is however important to understand that when you rollout the deployment to a previous revision or to some specific revision then it might fail due to changes done in mostly ConfigMap or Secrets. So to make the deployment successful, those also needs to be updated accordingly.
Step 4: Verify Deployment
Once the deployment is completed successfully, you can verify it by running
kubectl get deployments command as shown below.
[cyberithub@node1]$ kubectl get deployments
You can also check the output in YAML format by using
-o yaml with the above command as shown below.
[cyberithub@node1]$ kubectl get deployments app-fscm -o yaml