Helm Create Part 1: Templating

Matt Kornfield
4 min readDec 28, 2022

A guide to the output of running helm create with a focus on the metadata and templating.

Photo by Glenn Carstens-Peters on Unsplash

Prerequisites

If you’re new to helm , it’s one of the main ways people package, template and install applications in Kubernetes.

The install instructions page boils down to:

  • On a Mac:brew install helm
  • On a Windows w/ chocolatey: choco install kubernetes-helm
  • Some Linux flavors: sudo apt-get install helm

Let’s make a chart!

A chart is the name of any package that helm can create, install, depend on, or release. Charts are the building blocks of the helm world.

helm create my-first-chart will make your first chart. We’ll go through the items made by this command one by one. The ones without an hourglass we’ll go over in Part 2.

$ tree -a .
├── .helmignore ⏳
├── 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, 11 files

.helmignore

Not much different than a .gitignore, this will stop files from getting put into the tar file when you run helm package .

Chart.yaml

This contains all the metadata about your chart. Most of the files in a helm chart will be in YAML format, e.g.

key: value
aList:
- 1
- 2
- 3

The keys in the Chart file are well commented, so I won’t add much here. When you use things like helm repo search and look for your chart, the name, description and version from this YAML file will power that search view.

If you want to add dependencies to your chart (e.g. add redis or an RDBMS chart), you would add a dependency block like so

dependencies:
- name: nginx-ingress
version: "0.15.2"
repository: "https://helm.nginx.com/stable/"

And then with helm dependency update you’d have the other chart pulled down… but that’s probably a future lesson. Let’s go back to the starter chart.

Charts/ Folder

This empty folder will hold any dependencies you create within the Charts.yaml file. They’ll get pulled down by running the command mentioned above. But your brand new chart doesn’t have any dependencies, so we can ignore it.

NOTES.txt

If this is your first time looking at helm charts, you’re probably wondering “what the heck is up with all the {{ .Values.stuff }} . Well I mentioned the word template earlier, and that is a big part of what helm gives you.

In the Kubernetes world, everything is YAML (or JSON) files that represent resources. If you want to introduce options to change from a default set of files (instead of using something like the Kubernetes client), you can:

  • Template using something like helm
  • Patch files using something like kustomize
  • Do a simple find and replace with any tool of your choice (sed?), then doing kubectl apply

But helm goes the path of templating, and their docs on it are pretty good. Basically things inside {{}} get substituted with variable values or fancy expressions.

All this NOTES.txt file does is print out after your chart is installed. Plain and simple. It will use this nice templating to fill out some sample commands so that a user could look at the Service you’re running using kubectl commands.

_helpers.tpl

This might be the most WTF file. Essentially it defines all the chart level “variables” that are reused throughout the different YAML files. Variables defined in here are referenced with the include syntax, e.g. include “my-first-chart.fullname” . . The dot is important! Something from Go templating, which is what a lot of the helm templating is based around.

Anyway, this file can be hard to look at but it is important, since it creates a set of variables that are reused across all the chart. 43 pairs of double curlies at the time of this writing!

You’ll notice most of these labels are truncated to 63 characters. That pattern is due to the DNS resolution within kubernetes, and the limit of each part of a hostname being limited to 63 chars.

These go templating blocks define the following:

  • my-first-chart.name — The name of the chart, used in the NOTES text and also in the selector labels, which we’ll get to in part 2.
  • my-first-chart.fullname — The full name of the chart, which is used to name most of the resources that we’ll go over in part 2.
  • my-first-chart.chart — The name of the chart, only used in the selector labels
  • my-first-chart.labels — Labels used for every resource in the application. Can be good if you’re trying to describe/ get those resources by labels instead of names.
  • my-first-chart.selectorLabels— These labels are just for matching the deployment to the service. I’ll explain this better in part 2 as well.
  • my-first-chart.serviceAccountName — The name of the service account resource. This one is specifically templated because people tend to override service account names to reuse existing ones, created outside of the helm install.

values.yaml

This file is well self documented with comments. The thing to draw attention to with this values file is that it is the default set of values that will be passed into the chart. You can install a chart with -f my-values.yaml to provide overrides, or other options like --set.

Certain pieces are commented out in here for reference, like the resources , but you’ll probably want at least set the memory. If you want to change the name of the resources/ the chart, you’ll see nameOverride and fullnameOverride in here, which let you tweak the properties name and fullname we went over from _helpers.tpl

That’s all for now!

In Part 2 we’ll go over all the resources at a high level and the test file. Click here to read on.

--

--

Matt Kornfield
Matt Kornfield

Written by Matt Kornfield

Today's solutions are tomorrow's debugging adventure.

No responses yet