k8wiz
Back to Articles

Ready to test your Helm knowledge? Try our Helm quiz!

How to debug Helm template rendering errors

Read Helm 4 template errors, render one file with --show-only, fix nil pointers and nindent mistakes, and catch bad values with required and a schema.

10 min read
By k8wiz Team
  • helm
  • troubleshooting
  • templates
  • debugging

A chart that worked yesterday now fails with a wall of text that mentions executing, nil pointer or YAML parse error. Helm renders every template in memory before it sends anything to the cluster, so most of these failures can be reproduced and fixed on your laptop. This guide walks through reading the error, reproducing it locally and fixing the usual causes. The commands and outputs come from Helm 4.3.2, using a chart called web created with helm create web.

Reading the error message

Helm fails at one of three stages, and the first words of the error tell you which. A parse error means the Go template syntax itself is broken, such as a misspelled function or a missing {{ end }}. Helm reports the file and line, and nothing is rendered.

Error: parse error at (web/templates/secret.yaml:1): function "qoute" not defined

An execution error means the syntax was fine but something failed while the template ran. Helm 4 prints the file, line and column, then the action that failed, then the reason. When the failure happens inside an include, you get one block per level, from the template you rendered down to the helper that broke, so read it from the bottom up.

Error: web/templates/configmap.yaml:6:21
  executing "web/templates/configmap.yaml" at <.Values.database.primary.host>:
    nil pointer evaluating interface {}.primary

A YAML parse error means every template rendered, but the text it produced isn't valid YAML. Helm only knows which file broke. The line number refers to the rendered output, not to your template source, which is why it often points at a line that looks fine in your editor.

Error: YAML parse error on web/templates/configmap.yaml: error converting YAML to JSON: yaml: line 5: mapping values are not allowed in this context

Step 1: reproduce the failure with helm template

Debugging an install or upgrade against a live cluster is slow, and every attempt touches shared state. helm template runs the same rendering code locally and prints the manifests instead of applying them. It doesn't contact the cluster unless you ask it to.

The trick is to render with the same values the failing command used. If the failure came from an upgrade of an existing release, export the values that release was installed with and add whatever your pipeline passes on top.

helm get values web -n shop -o yaml > current-values.yaml
helm template web ./web -n shop -f current-values.yaml -f values-prod.yaml

When the error appears here too, you can iterate on the chart without touching the cluster. If it doesn't, the difference is in the values or in something that only exists in the cluster, which Step 8 covers.

Step 2: narrow the output with --show-only

A real chart renders hundreds of lines, and the one you care about is easy to lose. The --show-only flag, or -s, prints only the manifests that came from the template paths you name. Paths are relative to the chart root, the flag can be repeated, and it accepts glob patterns.

helm template web ./web -s templates/configmap.yaml
helm template web ./web -s 'templates/service*.yaml'

Keep in mind that --show-only filters the output. Helm still renders every template in the chart, so a broken deployment.yaml makes the command fail even when you asked to see only configmap.yaml. If you name a path that the chart doesn't have, Helm says so instead of printing nothing.

Error: could not find template templates/nothere.yaml in chart

Step 3: fix nil pointer errors on nested values

The nil pointer error in the first section came from this line in a new ConfigMap template.

data:
  DB_HOST: {{ .Values.database.primary.host | quote }}

The values file has no database key at all. Reading a missing key returns nothing, and Go templates allow that at one level. Trying to read primary from that nothing is what fails, so the field named in the message is the one after the missing key. In this case interface {}.primary tells you database is the key that doesn't exist.

The cleanest fix is a default in values.yaml that declares the whole structure, because it also documents the setting for users of the chart.

database:
  primary:
    host: ""

When the block is truly optional, guard the template instead. with skips its body when the value is empty, and a default dict at each level gives you an empty map to read from. Wrapping each step in parentheses also works, since reading a field from a missing map inside parentheses returns nothing instead of failing.

data:
  {{- with .Values.database }}
  {{- with .primary }}
  DB_HOST: {{ .host | quote }}
  {{- end }}
  {{- end }}
  {{- $db := .Values.database | default dict }}
  {{- $primary := $db.primary | default dict }}
  DB_HOST_OR_DEFAULT: {{ $primary.host | default "localhost" | quote }}
  DB_HOST_PARENS: {{ ((.Values.database).primary).host | default "localhost" | quote }}

The Sprig dig function looks like the obvious tool for this, but it only accepts a plain map. Passing .Values directly fails with interface {} is common.Values, not map[string]interface {}. Convert it first.

  DB_HOST: {{ dig "database" "primary" "host" "localhost" .Values.AsMap | quote }}

Step 4: find indentation mistakes with --debug

Indentation bugs produce the YAML parse error. A typical case is a helper included with indent after a {{- that removed the preceding newline.

metadata:
  name: {{ include "web.fullname" . }}
  labels:
    {{- include "web.labels" . | indent 4 }}

Without the --debug flag, helm template stops at the error and suggests the flag. With it, Helm prints the rendered YAML it couldn't parse and then the error. The debug log lines go to stderr, so the manifest on stdout stays clean.

helm template web ./web --debug -s templates/configmap.yaml
---
# Source: web/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: web
  labels:    helm.sh/chart: web-0.1.0
    app.kubernetes.io/name: web
    app.kubernetes.io/instance: web
    app.kubernetes.io/version: "1.16.0"
    app.kubernetes.io/managed-by: Helm

Count lines from apiVersion, skipping the # Source comment, and line 5 is the labels: line with the first label glued to it. The {{- removed the newline, and indent only adds spaces, so nothing put the newline back. Use nindent, which adds a newline before indenting, and the output becomes valid.

  labels:
    {{- include "web.labels" . | nindent 4 }}

The --debug output only helps with this kind of error. Helm suggests the flag after parse and execution errors too, but those stop rendering before any YAML exists, so the flag adds log lines and nothing else.

Step 5: fail early with required and fail

Nil pointers and empty strings make poor error messages for the people installing your chart. The required function stops rendering with your own message when a value is nil or an empty string. The fail function stops with a message whenever it runs, so you put it inside a condition that checks combinations of values.

data:
  DB_HOST: {{ required "database.host is required" .Values.database.host | quote }}
  {{- if and .Values.database.tls (not .Values.database.caSecret) }}
  {{- fail "database.caSecret must be set when database.tls is true" }}
  {{- end }}

Both produce an execution error that carries your message and the position of the call.

Error: execution error at (web/templates/configmap.yaml:6:14): database.host is required

Step 6: validate values with a schema

Template checks run one at a time, and rendering stops at the first one that fails. A values.schema.json file in the chart root is checked against the merged values before any template runs, and Helm reports every violation it finds in one go. It runs on install, upgrade, template and lint.

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "required": ["database"],
  "properties": {
    "replicaCount": { "type": "integer", "minimum": 1 },
    "database": {
      "type": "object",
      "required": ["host"],
      "properties": {
        "host": { "type": "string", "minLength": 1 },
        "tls": { "type": "boolean" },
        "caSecret": { "type": "string" }
      }
    }
  }
}

The errors give a JSON pointer to each bad field, grouped by chart, so problems in subchart values are easy to tell apart.

helm template web ./web --set database.host=db --set replicaCount=0 --set-string database.tls=yes
Error: values don't meet the specifications of the schema(s) in the following chart(s):
web:
- at '/database/tls': got string, want boolean
- at '/replicaCount': minimum: got 0, want 1

If you need to render a chart whose schema is wrong, --skip-schema-validation turns the check off for that command.

Step 7: run helm lint in CI

helm lint renders the chart, parses the output as YAML and checks the chart's metadata. It reports nil pointers, broken YAML and schema violations as [ERROR] lines, and exits non-zero when a chart fails. Pass the same values files your environments use, because a chart can lint cleanly with its defaults and break with production values.

helm lint ./web -f values-prod.yaml --strict

Lint has one blind spot that surprises people. It renders in a lint mode where required and fail don't stop rendering. A missing required value shows up only as a log line, and the chart still passes.

level=WARN msg="missing required values" message="database.host is required"
==> Linting ./web
[INFO] Chart.yaml: icon is recommended

1 chart(s) linted, 0 chart(s) failed

The --strict flag doesn't change this, since it applies to lint's own warnings. To catch missing required values in CI, run helm template with each environment's values as well, and let a non-zero exit fail the job. A schema with required and minLength also catches them, because lint does enforce the schema.

Step 8: check against the cluster with --dry-run=server

Some errors only exist in a real cluster. A template might branch on .Capabilities.APIVersions, read an existing Secret with lookup or render a kind whose CRD isn't installed. By default helm template uses a built-in list of API versions and a lookup that always returns an empty result, so those paths look fine locally.

Helm 4 has two dry-run modes on install, upgrade and template. --dry-run=client renders without any cluster connection. --dry-run=server connects to the cluster, reads its real capabilities, runs lookup against it, resolves every rendered kind against the cluster's API and checks for objects that already exist and belong to something else. Neither mode creates the release.

A server dry run is still not a full rehearsal. Helm stops before it sends any object to the API server, so admission webhooks and quota checks never see the manifests. A policy rejection can still appear on the real upgrade after a clean dry run.

helm upgrade --install web ./web -n shop -f values-prod.yaml --dry-run=server

A bare --dry-run with no value still works but logs a deprecation warning and means client. On helm template, --dry-run=none is rejected, since that command never installs anything. The old helm template --validate flag is deprecated in favor of --dry-run=server.

A dry run of install or upgrade prints every rendered Secret in plain text, in either mode. Add --hide-secret to those commands when the output ends up in CI logs.

Test yourself

Ready to test your Helm knowledge? Try our Helm quiz!