Introduction to Helm

Posted on Mar 4, 2022
Note: This article was written a while ago and may contain outdated information. Please verify the details before relying on it. If I express opinions or recommendations, they might not reflect my current views. For this reason, I recommend checking for more recent articles on the same topic.

Managing YAML-files for Kubernetes can be sometimes really complicated: You have multiple files which describe for Kubernetes how to deploy the application. You have for example a Deployment, a Service, a ConfigMap and a Secret. All that files describe one desired state of your application.

Managing all of these files and keeping an overview of all them can get a little bit hard.

Furthermore you can’t reuse these deployment files for another deployment without copying them and changing what you need for this other deployment.

Helm-Charts

Helm helps with managing all these different YAML-files by grouping them into one file - called chart (or also a template).

A chart has at minimum name, a description and a version.

E.g. of this minimum Chart.yaml file:

apiVersion: The chart API version (required)
name: The name of the chart (required)
version: A SemVer 2 version (required)

The directory structure

You can create a chart with the following command:

helm create new-chart

This will create a new directory which contains the chart structure. In the created templates directory are the Services, Deployments and other Kubernetes objects grouped.

When you want to bring your existing application into a Helm chart, you just need to replace these files with your existing ones.

The command from above will create the following directory structure:

new-chart
β”œβ”€β”€ Chart.yaml
β”œβ”€β”€ charts
β”œβ”€β”€ templates
β”‚   β”œβ”€β”€ NOTES.txt
β”‚   β”œβ”€β”€ _helpers.tpl
β”‚   β”œβ”€β”€ deployment.yaml
β”‚   β”œβ”€β”€ hpa.yaml
β”‚   β”œβ”€β”€ ingress.yaml
β”‚   β”œβ”€β”€ service.yaml
β”‚   β”œβ”€β”€ serviceaccount.yaml
β”‚   └── tests
β”‚       └── test-connection.yaml
└── values.yaml

3 directories, 10 files

Lets have a quick look at it:

  • templates/ directory contains all template files which will be evaluated by Helm.
  • NOTES.txt is the help text of the chart and will be displayed when the user runs helm install.
  • _helpers.tpl is the place to put template helpers in.
  • values.yaml contains the default values of a chart.
  • Chart.yaml contains the description of a chart.
  • charts/ can contain other charts (also subcharts).

Injecting parameters (.Values)

With the generated chart you can reduce the number of your YAML-files by just injecting parameters into the templates.

When you open the service.yaml which was generated by Helm you see the following:

apiVersion: v1
kind: Service
metadata:
  name: {{ include "new-chart.fullname" . }}
  labels:
    {{- include "new-chart.labels" . | nindent 4 }}
spec:
  type: {{ .Values.service.type }}
  ports:
    - port: {{ .Values.service.port }}
      targetPort: http
      protocol: TCP
      name: http
  selector:
    {{- include "new-chart.selectorLabels" . | nindent 4 }}

As you see there are some values which are in curly braces, which is an indicator for the Go templating language, which Helm is using.

The following line makes use of the parameter service.type:

spec:
  type: {{ .Values.service.type }}

.Values parameters are accessed from the values.yaml file.

If you open up the values.yaml you can see that it was set to ClusterIP:

service:
  type: ClusterIP
  port: 80

Other values

In some cases you will also find the access to a .Chart value. This is some metadata of a Helm Chart which are accessed from the Chart.yaml file. The Chart.yaml file has its own structure and doesn’t allow the values which are not defined by Helm itself.

There are also other values which you can find in the documentation

Render the templates locally

If you want to see which values get populated by Helm, you can run the helm template command, so that you don’t need to deploy your application to check which parameters get used!

helm template [NAME] [CHART]

E.g.:

helm template my-app new-chart

Overriding default values

If you want to override the default values of a Helm chart (like e.g. of a download helm chart), you need to create a new YAML-file which contains these values.

You don’t need to copy the whole values.yaml file, you just can override the ones you want and install the Helm Chart by handing over this file:

helm install -f myvals.yaml ./new-chart

Another form of injecting parameters is via the CLI --set option:

helm install --set param=val

And this is the key feature of Helm, which makes our YAML-files generic!

Further reading

Want to know more?

Keep on reading and choose one of the related articles. You can also check the home page for my latest thoughts, notes and articles.