A complete guide to helm charts

Shishir Khandelwal
3 min readAug 22, 2021

--

Helm charts let you simplify your Kubernetes deployment strategies. By using helm, you can keep all your configurations in a single file which makes the management of configurations easier.

Helm has additional features as well like keeping a track of the modifications and easy rollback strategies.

These are the reasons why Helm is the preferred way to deploy inside Kubernetes.

In this article, we will cover the basics of helm by following the below steps:

  1. Installing helm.
  2. Getting familiar with helm charts.
  3. Tracking changes to a chart.
  4. Rollbacks.
  5. Strategy for moving existing workload into a helm chart.

Let’s begin.

Step 1: Installing helm.

  • It’s really simple. Just download a shell script from Helm and execute it. The script will install it on your system.
  • Execute the below commands.
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3chmod 700 get_helm.sh./get_helm.sh

Step 2: Getting familiar with helm charts.

  • A simple helm command lets you initialize a sample chart. This gives you a head start for using helm.
helm create mychart
  • This would create a directory called ‘mychart’. Let’s see the different components that get created for us. The components are:
  1. Values.yaml : This contain all the configurations for all the YAMLs.
  2. Chart.yaml : This contains data about the charts like name, version & description.
  3. Templates : This directory contains all the Kubernetes YAMLs.
  4. Subcharts : Helm lets you create sub-charts, all files relating to sub-charts go in this directory.
  • To install the chart, all the required YAMLs need to go to templates/ directory. And for the configurations which you want to fetch from values.yaml, a template has to be used.

For e.g. for fetching image names from values.yaml, the template may look something like this

# Snippet of templates/deployment-auth.yaml #---
---
labels:
name: auth
---
---
containers:
- name: sample
image: "{{ .Values.auth.image.name }}:{{ .Values.auth.image.version}}"
# Snippet of values.yaml #auth:
image:
name: auth-for-app
version: 1.2
  • To install the chart
helm install mychart ./mychart

Step 3: Tracking changes to a chart.

  • Let’s try to upgrade the helm chart. For instance, let’s change the image version from 1.2 to 1.3. To do so, we will have to first make the change in values.yaml and then execute
helm upgrade mychart ./mychart
  • For each upgrade, helm would keep a record of the changes which you made. To see the history.
helm history mychart
  • To describe each change that you are making, you can use the ‘description’ flag.
helm upgrade mychart ./mychart --description "First change"

This description will provide you a summary of the changes you have made. To see the history, you can run “helm history mychart” command again.

  • To see the values which were in the system for a particular revision.
helm get values mychart --revision <revision number>

Step 4: Rollbacks.

  • To roll back to a previous revision. This is where helm can be really useful!
helm rollback mychart <revision number>

Step 5: Strategy for moving existing workload into a helm chart.

  • In order to add an existing workload to a helm chart, first, create the YAML of the existing workloads in the templates directory.
# Example #
kubectl get deployment auth -o yaml > mychart/templates/auth-deploy.yaml
  • Clean this YAML by deleting the annotations, status, and all the other things that are not necessary. These things are added by Kubernetes during deployment.
  • In order for helm to control these objects, certain labels and annotations must be applied to the object.
kubectl annotate $KIND $NAME meta.helm.sh/release-name=$RELEASE_NAMEkubectl annotate $KIND $NAME meta.helm.sh/release-namespace=$NAMESPACEkubectl label $KIND $NAME app.kubernetes.io/managed-by=Helm# In our case #kubectl annotate deployment auth meta.helm.sh/release-name=mychartkubectl annotate deployment auth meta.helm.sh/release-namespace=defaultkubectl label deployment auth app.kubernetes.io/managed-by=Helm
  • Just run ‘helm upgrade mychart’ command now. After this, you can make changes to the deployment through values.yaml!

That’s all! You know the basics of helm now.

For more tips, tricks and tutorials about DevOps and related roles, connect with me @ https://www.linkedin.com/in/shishirkhandelwal/ .

Happy learning! Keep exploring!

--

--

Shishir Khandelwal
Shishir Khandelwal

Written by Shishir Khandelwal

I spend my day learning AWS, Kubernetes & Cloud Native tools. Nights on LinkedIn & Medium. Work: Engineering @ PayPal.

No responses yet