Helm Rollback: The Basics and a Quick Tutorial

What Is Helm? 

Helm is a package manager for Kubernetes, allowing simplified management of Kubernetes applications. It simplifies deploying, upgrading, and handling Kubernetes resources. Similar to other package managers like apt for Debian, Helm is crucial for maintaining large-scale Kubernetes clusters.

Helm uses charts, which are pre-configured packages of Kubernetes resources. These charts are reusable, making deployments repeatable and easily upgradable. Through charts, administrators avoid the repetitive task of manually entering resource configurations, improving consistency and reducing human error.

This is part of a series of articles about Kubernetes Helm

Understanding the Helm Rollback Command 

The helm rollback command is useful for managing Kubernetes deployments, allowing administrators to revert to a previous release. This functionality is critical when a new deployment introduces errors or instability, ensuring that applications can quickly return to a known good state.

To perform a rollback, Helm uses the helm rollback command followed by the release name and the desired revision number. The command relies on the release history maintained by Helm, which records each deployment as a revision. By specifying a revision, Helm replaces the current state with the specified version, applying all configurations and settings from that revision.

Helm’s rollback capability supports various scenarios, including immediate reversion to the last known stable release or selective reversion to a specified prior state based on detailed release history analysis. This flexibility is useful in dynamic environments requiring rapid response.

Related content: Read our guide to Helm values.

Benefits of Helm Rollback 

The rollback capability in Helm offers several benefits:

  • Fault tolerance: Helm provides immediate recovery options in case of deployment failures. When issues arise, the rollback command ensures minimal downtime, maintaining application availability.
  • Risk mitigation: Regularly releasing updates without an efficient rollback mechanism could expose applications to failures, potentially harming user trust and company reputation. The ease of rolling back in Helm helps developers respond to these risks quickly and minimizes the need for extensive pre-release testing. 
  • Time efficiency: Helm rollback is fast, reducing operational downtime and allowing teams to focus more on forward-moving tasks rather than disaster recovery. It eliminates the need for time-consuming manual rollbacks or redeployments, which can be error-prone. 
expert-icon-header

Tips from the expert

Itiel Shwartz

Co-Founder & CTO

Itiel is the CTO and co-founder of Komodor. He’s a big believer in dev empowerment and moving fast, has worked at eBay, Forter and Rookout (as the founding engineer). Itiel is a backend and infra developer turned “DevOps”, an avid public speaker that loves talking about things such as cloud infrastructure, Kubernetes, Python, observability, and R&D culture.

In my experience, here are tips that can help you better utilize Helm rollback:

Gradual deployments:

Test deployments in non-critical environments before promoting them to production environments.

Leverage Helm hooks:

Use Helm hooks to automate pre- and post-rollback tasks. This can include running database migrations, clearing caches, or notifying relevant teams about the rollback status..

Integrate with service meshes:

 If you’re using a service mesh like Istio or Linkerd, leverage their traffic management capabilities to route traffic away from problematic deployments and toward stable releases during a rollback.

Monitor Helm rollback metrics:

Set up monitoring and alerting specifically for Helm rollback metrics. Tools like Prometheus and Grafana can track the success rate, duration, and performance impact of rollbacks.

Establish a rollback approval process:

Create a formal approval process for rollbacks involving key stakeholders. This ensures that rollbacks are executed thoughtfully, considering the potential impact on various aspects of the application and business.

Tutorial: How to Roll Back to the Previous Release in Helm 

Rolling back to a previous release in Helm can save you from potential downtimes and issues caused by problematic upgrades. Below is a step-by-step guide on how to perform a rollback using Helm and kubectl.

Step 1: List Helm Releases

First, identify the release you want to roll back. Use the helm ls command to list all releases. Adding the -A flag lists releases across all namespaces:

helm ls -A

This command provides the names and details of all current releases, helping you locate the release you need to address.

Step 2: Check Release History

Next, determine the revision history of the release you want to roll back. Use the helm history command, providing your release name:

helm history [release_name]

For example, if your release name is stock-price-api, the command would be:

helm history stock-price-api

This will output a list of revisions along with their status, date, and description. It helps you decide which revision to revert to based on when the release was stable or functioning as expected.

Step 3: Perform the Rollback

Once you have identified the revision number, use the helm rollback command to revert to that specific revision. The syntax is:

helm rollback [release_name] [revision_no]

For example, to roll back stock-price-api to revision 1, you would use:

helm rollback stock-price-api 1

If you omit the revision number, Helm will rollback to the previous revision by default:

helm rollback stock-price-api

The output should be similar to this:

REVISION	UPDATED                 	STATUS    	CHART                	DESCRIPTION     
1 Fri Oct 11 03:25:21 2024 superseded stock-price-api-0.1.0 Install complete
2 Fri Oct 11 03:41:57 2024 deployed stock-price-api-0.1.0 Upgrade complete

Roll back to revision 1:

helm rollback stock-price-api 1

Advanced Rollback Options

Helm provides several advanced options to customize the rollback process:

  • --cleanup-on-fail: Cleans up resources if the rollback fails.
  • --dry-run: Simulates a rollback without making any changes.
  • --no-hooks: Disables hooks during rollback.
  • --wait: Waits for the rollback to complete successfully.

Example of an advanced rollback command:

helm rollback stock-price-api 1 --cleanup-on-fail --dry-run --no-hooks --wait

Best Practices for Using Helm Rollback 

Implementing effective rollback procedures is crucial for maintaining the stability and reliability of Kubernetes applications. Here are some key strategies to optimize the Helm rollback process:

  • Version control your Helm charts: Maintain version control for Helm charts to ensure you can track changes and revert to previous versions if needed. Using a version control system like Git allows you to manage changes effectively, collaborate with team members, and maintain a history of modifications, making it easier to identify and revert problematic changes.
  • Maintain regular backups: Regularly backup your release configurations and data to ensure you have reliable restore points. Backups are crucial for disaster recovery and allow you to revert to a known good state if something goes wrong.
  • Monitor releases: Implement monitoring tools to track the performance and health of releases. Monitoring allows for the early detection of issues, enabling prompt rollbacks before problems escalate. Use tools like Prometheus, Grafana, and Kubernetes’ built-in monitoring capabilities to keep an eye on key metrics such as resource usage, response times, and error rates.
  • Test rollback procedures: Regularly test the rollback procedures in a staging environment to ensure they work as expected. Simulate failure scenarios and practice rollbacks to identify potential issues and refine the process. This practice helps build confidence that the rollback strategy is reliable and can be executed smoothly during a real incident.
  • Automate rollbacks: Integrate Helm rollback commands into the CI/CD pipeline to automate the rollback process. Automation ensures that rollbacks are executed quickly and consistently, minimizing human error and reducing the time it takes to restore service after a failed deployment. Use tools like Jenkins, GitLab CI, or GitHub Actions to script and schedule rollbacks as part of the deployment strategy.
  • Implement health checks: Use health checks to automatically assess the state of your applications post-deployment. If an application fails a health check, the system can trigger an automated rollback, minimizing downtime and ensuring that only stable releases remain in production. Kubernetes offers native support for liveness and readiness probes, suitable for this purpose.

Visualizing and Managing Helm Deployments With Komodor

Komodor’s platform streamlines the day-to-day operations and troubleshooting process of your Kubernetes apps. Specifically when it comes to Helm Charts, Komodor’s platform provides you with a visual dashboard to view the installed Helm charts, see their revision history and corresponding k8s resources. It also allows you to perform actions such as rolling back to a revision or upgrading to a newer version.

At its core, the platform gives you a real-time, high-level view of your cluster’s health, configurations, and resource utilization. This abstraction is particularly useful for routine tasks like rolling out updates, scaling applications, and managing resources. You can easily identify bottlenecks, underutilized nodes, or configuration drift, and then make informed decisions without needing to sift through YAML files or execute a dozen kubectl commands.

Beyond just observation, Komodor integrates with your existing CI/CD pipelines and configuration management tools to make routine tasks more seamless. The platform offers a streamlined way to enact changes, such as scaling deployments or updating configurations, directly through its interface. It can even auto-detect and integrate with CD tools like Argo or Flux to support a GitOps approach! Komodor’s “app-centric” approach to Kubernetes management is a game-changer for daily operational tasks, making it easier for both seasoned DevOps engineers and those new to Kubernetes to keep their clusters running smoothly, and their applications maintaining high-availability.

To learn more about how Komodor can make it easier to empower you and your teams to manage & troubleshoot K8s, sign up for our free trial.