Helm charts

Writing a chart

helm create myapp
myapp/
  Chart.yaml          # metadata: name, version, appVersion   (required)
  values.yaml         # default values                        (required)
  charts/             # dependency charts
  crds/               # CRDs, installed before everything else
  templates/          # the manifests, as Go templates
    _helpers.tpl      # reusable macros

version is the chart version (SemVer 2, ends up in myapp-0.1.0.tgz); appVersion is the version of the software inside.

Templates

NamespaceSource
.Valuesvalues.yaml, overridden by -f and --set
.ChartChart.yaml
.Release.Release.Name, .Namespace, .Revision - set at install time
metadata:
  name: {{ include "myapp.fullname" . }}
spec:
  replicas: {{ .Values.replicaCount }}
  template:
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"

Useful: default, quote, required "message" .Values.x, {{- ... -}} to trim whitespace, {{ if }} / {{ range }}, and include for helpers.

The loop

graph LR A[edit templates/values] --> B[helm lint] B --> C[helm template ./myapp] C --> D[helm install --dry-run --debug] D --> E[helm install / upgrade] E --> A
helm lint myapp
helm template ./myapp                          # render locally, no cluster needed
helm install demo ./myapp --dry-run --debug    # render and validate server-side
helm package myapp                             # -> myapp-0.1.0.tgz

Render before you install. Nearly every chart bug is visible in the rendered YAML - wrong indentation, an empty value, a missing quote around a number.

References