Introduction
Helm templates use Go's text/template engine to render Kubernetes manifests from chart templates and values. When a template references a value that is nil or missing from the values.yaml file or the --set overrides, the template rendering fails with a nil pointer error. This prevents any resources from being created or updated.
Symptoms
helm installorhelm templatefails withnil pointer evaluating interface- Error message points to the specific template file and line number
- Chart works with default values but fails with custom values overrides
- Template uses
.Values.config.settingbutconfigorsettingis not defined - Error message:
error calling include: template: no value "myValue" in .Values
Common Causes
- Values override file missing a required key that the template expects
- Typo in the value path (e.g.,
.Values.replicaCcountinstead of.Values.replicaCount) - Conditional template block not checking for nil before accessing nested values
- Merged values from multiple override files creating unexpected nil values
- Helm subchart values not properly namespaced under the subchart name
Step-by-Step Fix
- 1.Identify the nil value from the error message: Find the missing key.
- 2.```bash
- 3.helm template my-release ./chart -f values.yaml 2>&1 | grep -i "nil"
- 4.
` - 5.Check the values.yaml for the missing key: Verify the value exists.
- 6.```bash
- 7.yq eval '.image.repository' values.yaml
- 8.# Returns null if the key is missing
- 9.
` - 10.Add the missing value with a default: Update values.yaml.
- 11.```yaml
- 12.# values.yaml
- 13.image:
- 14.repository: myapp
- 15.tag: "1.0.0"
- 16.pullPolicy: IfNotPresent
- 17.
` - 18.Add nil checks in the template for optional values: Make the template resilient.
- 19.```yaml
- 20.# templates/deployment.yaml
- 21.{{- if .Values.config }}
- 22.env:
- 23.{{- range $key, $value := .Values.config }}
- 24.- name: {{ $key }}
- 25.value: {{ $value | quote }}
- 26.{{- end }}
- 27.{{- end }}
- 28.
` - 29.**Use the
defaultfunction for values with sensible defaults**: Provide fallback values. - 30.```yaml
- 31.replicas: {{ .Values.replicaCount | default 1 }}
- 32.image: {{ .Values.image.repository | default "nginx" }}:{{ .Values.image.tag | default "latest" }}
- 33.
`
Prevention
- Define all required values with defaults in the chart's default values.yaml
- Use
requiredfunction for mandatory values with clear error messages - Run
helm lintandhelm templatein CI/CD pipelines before any install or upgrade - Maintain a schema.json file for values validation with
helm schemaplugin - Document all required and optional values in the chart's README with examples
- Test chart rendering with minimal values (only required keys) to catch nil references