Skip to main content

TASK 78: Rollback a Deployment in Kubernetes

Requirements

This morning the Nautilus DevOps team rolled out a new release for one of the applications. Recently one of the customers logged a complaint which seems to be about a bug related to the recent release. Therefore, the team wants to rollback the recent release.

There is a deployment named nginx-deployment; roll it back to the previous revision.

Note: The kubectl utility on jump_host has been configured to work with the kubernetes cluster.


Note

This document focuses on the implementation approach. The task statement in Requirements is preserved as the source requirement.

Prerequisites

  • Access to the configured Kubernetes cluster from jump_host.
  • kubectl is configured and points to the correct context.
  • Use the task-specified namespace, resource names, and images exactly.

Steps

Always check the running deployment and resources first before doing any changes.

~$ kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deployment 1/3 1 1 15s

~$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-deployment-5946cc7684-68c5v 1/1 Running 0 12s
nginx-deployment-5946cc7684-h5kq2 1/1 Running 0 16s
nginx-deployment-5946cc7684-klk5j 1/1 Running 0 26s

To rollback to a previous realease, we can use the rollout undo command.

kubectl rollout undo deployment nginx-deployment

We can verify if the rollback was successful by using the rollout status command.

~$ kubectl rollout status deployment nginx-deployment

deployment "nginx-deployment" successfully rolled out

Verification

  • Confirm the required pods/services/deployments/jobs are in the expected state.
  • Run kubectl get commands for the affected resource types and namespace.

Resources