Sub topic 8
Linting and debugging rendered manifests
This chapter assumes you can read Go template syntax in Helm charts, know the webapp chart layout from earlier chapters, and can run kubectl against a cluster. You will learn to catch mistakes before they reach the cluster by linting, rendering, and doing dry runs.
The three checks
Helm gives you three levels of checking. Each catches different errors.
| Command | Needs a cluster | What it catches |
|---|---|---|
| `helm lint` | No | Bad `Chart.yaml`, YAML syntax errors, template errors, schema violations |
| `helm template` | No | Template logic errors, and the final YAML you would apply |
| `helm install --dry-run` | Yes | Everything above, plus cluster-side validation and lookups |
Run them in this order, from cheapest to most thorough.
helm create webapp
helm lint ./webapp
helm template my-release ./webapp --set replicaCount=3
helm install my-release ./webapp --namespace demo --create-namespace --dry-run --debugLinting a chart
helm lint examines the chart and reports messages at three levels: INFO, WARNING, and ERROR. Any ERROR makes the command exit with a non-zero status, so it works well as a CI gate.
helm lint ./webapp --set replicaCount=3Lint renders the templates with your values, so pass the same --set or -f options you use at install time. If the chart has a values.schema.json, lint also checks your values against it.
Lint is not a full validator. It does not know whether apiVersion: apps/v1 and the fields under spec are valid for your cluster version.
Rendering locally with helm template
helm template renders every template and prints the YAML to standard output. It never contacts the cluster. The first argument is the release name, which fills .Release.Name.
helm template my-release ./webapp --set replicaCount=3Check the output for the values you expect. With replicaCount=3, the Deployment should contain replicas: 3.
To render one file, use --show-only:
helm template my-release ./webapp -s templates/deployment.yamlPipe the output to kubectl apply --dry-run=client -f - for a basic structural check against the schemas that kubectl knows.
Dry runs against the cluster
helm install --dry-run renders the chart and sends it through the install process without creating resources. Add --debug to print the computed values and the rendered manifests. Use --dry-run=server to make the API server validate the objects. Plain --dry-run renders client-side only and does not contact the API server.
Use this check when your templates call lookup or depend on cluster capabilities such as .Capabilities.APIVersions. helm template cannot evaluate those the way a live cluster can.
Reading errors
Template errors name the file and line. Three errors are common.
- Nil pointer. The error
nil pointer evaluating interface {}.repositorymeans a value is missing. Here.Values.imageis not defined, so.repositoryfails. Check the key spelling and indentation invalues.yaml. - YAML parse error. The template rendered, but the result is not valid YAML. Usually the cause is indentation, for example an
includewithoutnindent. Look at the rendered output, not the template. - Wrong type. A value such as
"true"(a string) is nottrue(a boolean). Quote values withquotewhen Kubernetes expects a string.
When the output is hard to inspect, add a temporary debugging line to a template.
# {{ .Values | toYaml | nindent 2 }}Helm still evaluates the action inside the YAML comment, so the values appear in the rendered output. Remove the line when you are done.
For a value you are unsure about, use fail to stop with a clear message, or required to demand a value:
image: "{{ required "image.repository is required" .Values.image.repository }}"A debugging workflow
The diagram shows the order to follow when a chart fails.
Inspecting an installed release
After an install, you can see what Helm actually applied:
helm get manifest my-release -n demo
helm get values my-release -n demo --allhelm get manifest shows the rendered YAML stored in the release. --all on get values includes chart defaults along with your overrides. Compare these with your local helm template output to find differences.
Exercise
A teammate runs helm template my-release ./webapp and the output looks correct, but helm install fails because a template uses lookup to read an existing Secret. Why did helm template not reveal the problem, and which command should they run instead?
Show answer
helm template renders without contacting the cluster, so lookup returns an empty result and cannot show the real behavior. They should run helm install my-release ./webapp --dry-run=server --debug (or a plain --dry-run --debug against the cluster) so the template is evaluated with a live connection, then check the rendered output.