Skip to content

Lesson 2 of 9 · 24m

Authoring Charts People Can Operate

Template structure, helper conventions, values schemas, and rendering tests that make charts boring to consume and safe to change.

A production chart has two audiences: the deploy pipeline that installs it and the human who has to understand it during an incident. Optimize for the second one. Clever Helm templating is a liability when the cluster is degraded and somebody is rendering YAML at 3 a.m.

Keep templates legible

charts/api/
  Chart.yaml
  values.yaml
  values.schema.json
  templates/
    _helpers.tpl
    deployment.yaml
    service.yaml
    serviceaccount.yaml
    ingress.yaml
    NOTES.txt
  tests/deployment_test.yaml

Put repeated labels and names in _helpers.tpl, not business logic. A helper that hides three lines of labels is useful. A helper that decides whether to create a database migration Job based on five nested conditions is not.

Use schema validation before the cluster does

values.schema.json is one of the highest-value features teams ignore. It fails fast when somebody passes replicaCount: "2" instead of 2, misspells resources, or forgets a required host.

{
  "type": "object",
  "required": ["image", "service"],
  "properties": {
    "image": {"type": "object", "required": ["repository", "tag"], "properties": {"repository": {"type": "string"}, "tag": {"type": "string", "minLength": 1}}},
    "replicaCount": {"type": "integer", "minimum": 1}
  }
}

Schema catches type mistakes before they become runtime incidents. It also documents the chart better than a README because it is executable.

Template the minimum surface

resources:
  {{- toYaml .Values.resources | nindent 12 }}

toYaml and nindent are appropriate when the input shape is genuinely arbitrary YAML, such as resources, env lists, or affinity. Do not use them to smuggle entire nested object models through values because you did not want to design an interface.

Test the rendered product

Unit-test charts with rendered-output assertions. helm unittest or even snapshot output in CI can verify that enabling ingress adds the expected host, that disabling persistence removes volume mounts, and that a required label stays present. The test target is rendered YAML, not template implementation details.

Field notes

  • Quote strings deliberately: {{ .Values.image.tag | quote }} prevents YAML from parsing 2026.11 as a number.
  • required is useful for values that must exist, but do not use it to paper over unclear chart design.
  • NOTES.txt should give operators the next useful command, not marketing copy.
  • A chart that supports every possible Kubernetes feature usually supports none of them well.

Was this lesson helpful?

Sign in to rate