Helm "YAML parse error ... did not find expected key" in CI
By Daniel Zoghalchali·Latchkey
After rendering, the output is not valid YAML. "did not find expected key" almost always means broken indentation, usually from a templated block inserted at the wrong column with nindent/indent.
What this error means
helm install/template fails with "Error: YAML parse error on my-app/templates/<file>.yaml: error converting YAML to JSON: yaml: line N: did not find expected key".
helm
Error: YAML parse error on my-app/templates/deployment.yaml: error converting YAML
to JSON: yaml: line 34: did not find expected key
Diagnose it: render the chart before you install it
Most Helm failures are visible in the rendered manifests. Template them locally with the same values CI uses and you will usually see the problem without touching the cluster.
Terminal
# what will actually be applied
helm template <release> <chart> -f values.ci.yaml | head -60
# validate against the live cluster schema without installing
helm install <release> <chart> -f values.ci.yaml --dry-run --debug
# what state is the release actually in?
helm history <release>
helm status <release>
Common causes
Wrong indentation from a templated block
A {{ toYaml .Values.x | indent 4 }} (instead of nindent) or the wrong indent count misaligns keys, producing structurally invalid YAML.
A bad value injected into a map
A multi-line or special-character value inserted without quoting breaks the surrounding mapping.
How to fix it
Render with --debug and inspect the YAML
Render the failing template so you can see the exact output.
Find the line the error names and check the indentation around it.
Switch indent to nindent or correct the column, then re-render.
Prefer nindent for block insertion and quote/toYaml for values so indentation and special characters stay valid.
templates/deployment.yaml
env:{{- toYaml .Values.env | nindent 8 }}
How to prevent it
Use nindent for inserted blocks and pick the correct column.
Quote string values that may contain colons or special characters.
Run helm template (and helm lint) in CI so YAML breaks surface before deploy.
Frequently asked questions
What causes Helm "YAML parse error ... did not find expected key" in CI?
There are 2 common causes: wrong indentation from a templated block and a bad value injected into a map. A {{ toYaml .Values.x | indent 4 }} (instead of nindent) or the wrong indent count misaligns keys, producing structurally invalid YAML.
How do I fix Helm "YAML parse error ... did not find expected key" in CI?
There are 2 fixes depending on which cause you have: render with --debug and inspect the yaml and use nindent and quote values. Work through them in order, since the first is the most common.
What does Helm "YAML parse error ... did not find expected key" in CI actually mean?
helm install/template fails with "Error: YAML parse error on my-app/templates/<file>.yaml: error converting YAML to JSON: yaml: line N: did not find expected key".
How do I stop Helm "YAML parse error ... did not find expected key" in CI happening again?
Use nindent for inserted blocks and pick the correct column. The prevention section lists 3 changes that keep it from recurring.