Data Engineering

The busy developer’s guide to Helm and Helm Charts

Posted by Chris

TLDR: Helm is a package manager for Kubernetes (think what brew is for MacOs, pip for Python).  Helm Charts are a collection of Kubernetes resource definitions.  A Chart should contain all resources for a single application.

Why use Helm?

Helm can make working with Kubernetes much easier.  With Helm, you can now manage multiple Kubernetes resource objects at the same time.

 Helm allows you to: 

  • Easily share charts and install 3rd party solutions from Helm Hub
  • Quickly deploy applications that may need many different microservices to run
  • Use Chart Templates to parameterize your application (ie. specify a deploy for staging environment only)

Read more about why teams are using Helm.

What is Helm?

Helm is a CLI tool to manage the installation of Kubernetes objects.  Here a are a few key terms to understand how Helm works:

  • Helm Chart – is the Kubernetes equivalent of a package.  It contains all the resources needed for a single application. 
    • Helm Charts follow a basic File Structure:
      • Chart.yaml – Basic info on this Chart.
      • Values.yaml – Default config values used by the templates.
      • charts/ – Other charts that this particular chart depends on.
      • crds/ – Kubernetes Custom Resource Definitions.
      • templates/ – Kubernetes definition files written with the Helm templating language.
  • Repository – a place to share and collect charts.  You can have your own repositories, or use Helm Hub.
  • Release – a single instance of an installed Chart. One chart can be installed many times into the same cluster.  Each install is a new Release with a unique release name.

Quoting the Helm Documentation, Helm installs charts into Kubernetes.  Installing a chart creates a new release for each time. And to find new charts, you can search Helm chart repositories.

How to Work with Helm

You’ll likely encounter Helm Charts when you have something to install in Kubernetes.  We will focus here on how to work with Helm Charts using Helm Templates.

Helm Templates are written in a hybrid template language.  It is based on the Go template language with some additional built-in functions provided by Helm.

Passing Values

Helm runs every file in the templates folder through it’s templating engine.  This is when the values are filled in to generate your actual Kubernetes manifest.  

Values come from two places. 

  1. The values.yaml inside of your chart directory (these are your default values)
  2. A YAML file or value(s) passed to the helm install command

Variable Namespaces

Any value provided is accessible in a template via the “.Values” object.  

The “.” acts as a namespace accessor.  The “.Values” is saying from the <root level> namespace give me what is in the Values namespace.

Helm has other pre-defined data that can be accessible in templates.  For example, “.Release.Name” or “.Chart.Version” are built-in values you can use.

Defining your own Values

When you get a Chart, you’ll likely need to configure it to suit your needs.  Most of the time you will be using option 2 above and creating a YAML file to pass to the helm install command.

Create a YAML file named whatever you’d like.  You can then structure this file however you choose.  Just be sure the template references follow the correct path to the value.  

For example, given this YAML file with two values defined:

Your template call to get the hostname would look like:

{{ .Values.connections.host }}

The structure of your YAML config can be anything you’d like.  It just needs to be consistent with how the values are referenced from the templates.

Testing locally

With Helm, you can run helm install using the –dry-run flag to simulate an installation.  This will attempt to render your Chart with the values passed to it.

Helm’s Debugging Templates section has a few more commands to use when developing a template.

For more information on Helm Templates, read the Helm Chart Template Guide.

Next Steps with Helm

Install Helm by following the instructions in the Helm Quickstart Guide.

Try it out

  1. Get Chart from Helm Hub or perhaps your organization
  2. Make your own custom YAML config 
  3. Try the –dry-run flag with helm install.  Include the -f flag to pass your own YAML file for the values.

More Reading