How to Rollback Your Kubernetes Deployment

If a new Deployment to your Kubernetes cluster is not stable, you may want to rollback to a prior version. In this guide, we'll show you how to do this with kubectl commands.

Patrick Londa
Mar 13, 2023
 min read
Share this post

If you encounter performance issues or bugs caused by a new Deployment to your Kubernetes cluster, you should rollback to a previous version while you investigate. By doing this, you’ll minimize downtime and be able to resolve issues like data loss or security vulnerabilities introduced by the new Deployment.

In this guide, we’ll show you how to roll back your Deployment, verify that it was successful, and get details about your problematic deployment.

How to Roll Back Your Kubernetes Deployment

You can use the kubectl commands to roll back to a previously tested Kubernetes Deployment. Here’s how:

  1. Type the command to obtain the list and status of all the Deployments in your cluster:
kubectl get deployments

You’ll see an output that looks like this:

nginx-deployment     3/3     3            3           30m
  1. Use the following command to obtain the revision history and the number of each revision for the Deployment you want to roll out. Here <deployment_name> is the name of the Deployment you want to roll back.
kubectl rollout history deployment/<deployment_name>

You’ll see an output that looks like this:

deployments "nginx-deployment"
1           kubectl apply --filename=
2           kubectl set image deployment/nginx-deployment nginx=nginx:1.12.1
3           kubectl set image deployment/nginx-deployment nginx=nginx:1.121

You can see in this example there is a typo in the 3rd revision, updating image “1.121” instead of image “1.12.1”.

  1. Next, type a rollout undo deployment command where <revision_number> is the specific number of the Kubernetes deployment you want to roll back to, and the undo command will deploy that revision. But you must remember to test the rollout in a staging environment for incident response before performing it in production, as it can have unintended consequences.
kubectl rollout undo deployment/<deployment_name> --to-revision=<revision_number>

How to Check if Your Rollback Was Successful

You can check whether the rollback to a previous Kubernetes Deployment was successful with a couple commands.

  1. This status command will show you the status of whether your rollback was successful or not:
kubectl rollout status deployment/<deployment_name> 

If the status displays a message like "successful rollout" or "rolled out," it means you succeeded in deploying the previous Kubernetes revision

  1. This command will show you the revision history of the deployment you rolled back to. Verify that the deployment has been updated correctly.
kubectl rollout history deployment/<deployment_name>

Automating Your Deployment Rollbacks with Blink:

Rolling back a problematic deployment isn’t hard, but it does require you to remember which commands to run and what information to look for. In the time it takes to manually rollback your deployment, your application may experience downtime or subpar performance.

With Blink, you can use event triggers like a PagerDuty or Datadog incident to automatically rollback to the previous deployment and update the incident ticket.

Blink Automation: Rollback Kubernetes Deployment and Resolve Datadog Incident
Blink Automation: Rollback Kubernetes Deployment and Resolve Datadog Incident

This automation in the Blink library is triggered when a related Datadog incident is created. When it runs, it does the following steps:

  1. Updates the incident timeline with the automation execution URL.
  2. Rolls back the Kubernetes Deployment.
  3. Runs a Service health-check.
  4. If the Service is healthy, it then resolves the Datadog incident.

You can import this automation from the library into your account and customize it based on your organization’s needs. For example, you can drag-and-drop new actions into the canvas to add notifications, approval steps, and conditional subflows.

You can also kick off other automations to gather troubleshooting information so your development team can quickly understand what went wrong.

With Blink, you can build your own automation from scratch or use one of our 5K pre-built automations today.

Get started with Blink today to see how easy automation can be.

Automate your security operations everywhere.

Blink is secure, decentralized, and cloud-native. 
Get modern cloud and security operations today.

Get a Demo