Helm

K8s packaging is a virtual concept. When we have several objects related to the same service, we can group them together in a single package. But there is no object in k8s for that. Helm manages a group of resources in a single unit. This is called a chart, which contains all the object required in the unit to make an application or service to work.

Helm charts

Once a chart is created, a new folder is created with all the files required for helm to work. This folder is called chart. Explanation of the files:

  • Chart.yaml: contains the metadata for the chart.
  • values.yaml: set of properties that can be used to configure the chart. This contains the default values.
  • charts folder: a Chart can depend on another Chart. If this happens, chart files will be inside this folder.
  • templates folder: contains the templates for the resources that will be created. Is where helm find the templates for all the k8s objects required for your application. May some files are autogenerated by default. If you have predefined k8s files, you can delete them and place your own k8s manifest in a folder called k8s. Usually, some tweaks to the files are required. For example, the name of the service, default values...
  • templates/NOTES.txt: contains the information that will be shown when the chart is installed.

Templates

A template is an intermediate file that will be used to generate the final k8s file. Representation is with {{ }}. For example, {{ .Values.image.repository }} will check in the values.yaml file, image object, and the value of key repository. In case --set is used, it will override the value in the values.yaml file.

Another objects are available to be used in the templates aside from .Values. Release (corresponding to the release data) and Chart (corresponding to the chart metadata).

Update a chart template will require an update of the version in charts.yaml.

Inside file _helpers.tpl there are some functions to be used in the templates. Use with {{ template "name" . }}. The dot is the context. You can also define your custom functions.

templates/NOTES.txt can also use templates related to the service, such as how to access the service or see secrets generated by helm.

Templates functions

  • range: is used to iterate over a list. Once we are inside the loop, context is modify with the entity we are iterated for.
  • default: in case the value is not provider or empty string, use the other value provided.
  • printf: to concatenate strings.
  • quote: quote a string.
  • pipeline functions like in bash.
  • if/else statements are available.

References