Rolling back to previous deployment of Kubernetes

Get started

We want to rollback to the previous deployment which simply means there is more than one deployments. You can rollback to any previous deployment which is available.

Version History

Let’s get the version history in the Shell (Terminal). Once we get our previous deployment information then we can rollback to that by specifying it’s information.

To get the history run this command in your shell.

$ kubectl rollout history deployment/<your-app-name>

For Example

Suppose I have a app name admin-api and I want to see the history of deployment then I will write this command kubectl rollout history deployment/admin-api. This command will list last two deployments.

$  kubectl rollout history deployment/admin-api
deployment.extensions/admin-api
REVISION  CHANGE-CAUSE
4         <none>
5         <none>

So, here is two REVISION of our deployment.

  • Greatest revision is always the live deployment. Here we revision 5 is live now.
  • We have other revision also which is smaller than greatest revision (5). All smaller are previous deployment.

From the version history it’s clear that most recent version is VERSION 5. We will go to the previous version which is 4

Rolling back

I am going to rolling back to previous version, which is 4 in our case.

  • --to-revision : You have to tell the revision number and it will rollback/undo to that deployment.
$ kubectl rollout undo deployment/admin-api --to-revision=4