Deploying Applications on Kubernetes with Helm: A Step-by-Step Guide

This article builds on the “What is Helm and how to install it on Ubuntu 20.04 server?” article. If you’re new to Helm, I recommend reading that first. Here, we’ll walk through how to release an Apache application from an existing chart, and explore the Helm commands to release, upgrade, rollback, delete, and restore a sample chart.

Essential Helm Commands

  • helm search: Search for Helm charts
  • helm repo: Manage repositories with operations like add, list, remove, update, and index
  • helm delete: Delete a release, removing all associated Kubernetes objects
  • helm status: Display the status of the release
  • helm create: Create a Helm chart
  • helm install: Install a chart with its Kubernetes objects
  • helm upgrade: Upgrade a release with modifications
  • helm history: View the release history
  • helm rollback: Revert a release to a previous version

For this guide, it is assumed that you are acquainted with the basics of Helm, have a Kubernetes cluster, and the Helm client is already installed.

Pre-requisites

  1. A Kubernetes Cluster with at least one worker node. Guide to create a Kubernetes Cluster on AWS EC2.
  2. Helm installed on your master node.

Objectives

  1. Release a sample chart from a repository.
  2. Create a chart and release a sample application.
  3. Upgrade the release.
  4. Restore the release after deletion.

Release a Sample Chart from the Repository

First, verify Helm’s availability on your server:

helm version

To install an Apache chart, search for it in the Helm hub:

helm search hub apache

Search a chart on Hub

Choose a URL from the results, copy it, and paste it into your browser. Follow the on-page commands to add the repo and install the chart.

Get a URL of the Repo of the Chart


helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo list
helm install my-release bitnami/apache

After successful installation, inspect the created Kubernetes objects:


kubectl get nodes
kubectl get pods
kubectl get pods -o wide
kubectl get svc
curl 10.244.1.2:8080

To delete the release, execute:

helm delete my-release

helm ls
helm status my-release

Delete the release

Create a Chart and Deploy a Sample Application

Create your own chart with a sample Nginx application:

helm create my-first-chart

Explore the newly created chart structure:


cd my-first-chart/
ls -l
ls -l charts/
ls -l templates/
ls -l templates/tests/

Create a Chart

Inspect Chart.yaml contents:


ls -lt
cat Chart.yaml

See Chart.yaml

Inspect values.yaml contents:


ls -lt
cat values.yaml

Deploy the application using your local chart:


kubectl get pods
helm install my-first-release my-first-chart/

Check the deployed pods and services:


kubectl get pods
kubectl get svc
curl 10.104.229.187

Review release details:


helm ls
helm status my-first-release

Upgrade the Release

Modify the replica count in values.yaml:


cat my-first-chart/values.yaml | grep replica
vim my-first-chart/values.yaml
cat my-first-chart/values.yaml | grep replica

Upgrade your release to apply changes:


helm upgrade my-first-release my-first-chart/

Verify updated revision and running pods:


helm ls
kubectl get pods

Check release history and rollback if needed:


helm history my-first-release
helm rollback my-first-release 1
kubectl get pods

Delete the sample application if required:


helm delete my-first-release

Restore the Release After Deletion

Roll back a deleted release by keeping its history:


helm install my-second-release my-first-chart/
helm delete my-second-release --keep-history
helm rollback my-second-release 1

Conclusion

In this guide, we explored how to deploy an application using Helm charts, create and release our own charts, upgrade releases, and manage rollbacks with history preservation even after deleting a release.


Frequently Asked Questions

  • What is Helm? Helm is a package manager for Kubernetes, helping to define, install, and upgrade even the most complex Kubernetes applications.
  • Do I need a Kubernetes cluster to use Helm? Yes, Helm requires a Kubernetes cluster to manage and deploy applications effectively.
  • How do I create a custom Helm chart? Use the command helm create to scaffold a new chart.
  • Can I rollback a release after deletion? Yes, use the --keep-history option when deleting a release to preserve its history and enable rollback.
  • What happens to my application when I delete a Helm release? All associated Kubernetes objects created by the release are deleted. However, if you use the --keep-history option, you can restore to the previous state.