Helm
Kubernetes
DevOps
Rollback
Software Deployment

Helm rollback to previous release

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

In the realm of Kubernetes, Helm has become the de-facto package manager, providing a simple way to deploy and manage applications. One of the critical features of Helm is its ability to manage application releases efficiently, allowing developers and operations teams to roll back to previous versions with minimal hassle. This article delves into the details of how Helm handles rollbacks, including the commands used, the technical underpinnings, and practical examples.

Understanding Helm Releases

Before diving into rollbacks, it's essential to understand how Helm handles releases:

  • Chart: A Helm package containing the Kubernetes resource definitions and some configuration files.
  • Release: An instance of a chart running in a Kubernetes cluster. Each release has a version number.
  • Revision: Each update to a release creates a new revision, making it possible to have a history of changes.

Helm stores release information such as configurations, charts, and hooks in a ConfigMap or a Secret, making it possible to track the history of a particular release.

The Helm Rollback Command

Syntax

The basic command for rolling back a release is:

bash
helm rollback <RELEASE_NAME> <REVISION>
  • <RELEASE_NAME>: The name of the release you want to roll back.
  • <REVISION>: The revision number you wish to roll back to.

If no revision is specified, Helm defaults to rolling back to the previous revision.

Example

Suppose you have a Helm release named my-app with several revisions. You can list these revisions using:

bash
helm history my-app

Assuming you have the following output:

 
1REVISION  UPDATED                   STATUS      CHART          APP VERSION
21         Fri May 21 15:05:27 2021  superseded  my-app-0.1.0   1.0
32         Fri May 21 16:21:12 2021  deployed    my-app-0.1.1   1.1
43         Fri May 21 17:45:13 2021  deployed    my-app-0.1.2   1.2

To roll back to revision 2:

bash
helm rollback my-app 2

After executing the rollback, Helm will redeploy the resources as defined in the chart's revision 2, effectively returning the application to its previous state.

How Helm Rollback Works

Technical Process

  1. Fetch Release Data: Helm retrieves the release data corresponding to the specified revision from the Kubernetes cluster.
  2. Redeploy Resources: Helm utilizes the data (manifests and templates) from the specified revision to redeploy the Kubernetes resources.
  3. Update Status: Upon success, Helm updates the release status and increments the revision number.

Hooks

Helm supports lifecycle hooks that can be used for certain actions during the release process, including rollbacks. Developers can specify custom hook actions in their chart’s templates.

Advantages of Helm Rollback

  • Simplicity: Provides a straightforward mechanism to revert applications to a stable state.
  • Configurability: Allows custom hooks to handle rollback-specific logic.
  • Efficiency: Leverages Kubernetes's declarative nature, ensuring a fast and efficient rollback process.

Considerations and Best Practices

  1. Database Migrations: Rollbacks can affect database states. Incorporate strategies to handle schema reversions safely.
  2. Configuration: Ensure configurations are backward-compatible whenever possible to facilitate smoother rollbacks.
  3. Testing: Regularly test rollback procedures as part of your CI/CD pipeline to ensure readiness during production incidents.

Example Use Case

Consider an e-commerce application with multiple dependencies. A new feature release inadvertently breaks the checkout process. By utilizing Helm’s rollback feature, the operations team can quickly revert to the previous stable release, minimizing downtime and revenue loss.

Summary

Helm's rollback feature is a vital component in modern Kubernetes operations, offering a simple yet powerful way to manage applications and handle unexpected issues. Here's a consolidated view:

FeatureDescription/Usage
Rollback Commandhelm rollback <RELEASE_NAME> <REVISION>
Revision StorageConfigMap / Secret in Kubernetes
Key BenefitQuick reversion to stable states
Best PracticeTest rollbacks regularly Plan for database handling

By mastering Helm rollbacks, teams can enhance their operational efficiency and ensure application availability, making it a must-know for anyone working with Kubernetes-based systems.


Course illustration
Course illustration

All Rights Reserved.