tmpl: Render Go Templates From the CLI
tmpl renders Go text/template files against a values file and the environment, a lightweight standalone alternative to Helm-style templating.
When you want Go template semantics (the same engine Helm and kubectl use) without pulling in Helm, a small tmpl binary renders a single template with a values file.
What it does
tmpl loads a Go text/template, merges a values file (YAML or JSON) and environment variables into the render context, executes the template, and prints the result. Sprig-style functions are commonly available for string and default handling.
Common usage
# render with a YAML values file
tmpl -f values.yaml template.tmpl > out.yaml
# use the Env map inside the template: {{ .Env.IMAGE }}
IMAGE=nginx:1.27 tmpl template.tmpl > out.yamlOptions
| Form | What it does |
|---|---|
| -f, --values <file> | YAML/JSON values file merged into the context |
| {{ .Values.x }} | Access a value from the values file |
| {{ .Env.NAME }} | Access an environment variable |
| {{ default "x" .Values.y }} | Sprig default when a value is missing |
In CI
Because it is the Go template engine, {{ .Values.foo }} on a missing key renders <no value> rather than erroring; guard optional fields with a default function or a {{ if }} so you do not ship a literal <no value> into a manifest. Render to an artifact and diff before apply, and pin the tmpl version for stable function sets.
Common errors in CI
"template: template.tmpl:N:M: executing ... at <.Values.foo>: nil pointer evaluating interface {}.foo" means a nested key is missing; use default or check with if. "function \"toYaml\" not defined" means the binary lacks a helper you assumed; stick to documented functions. A literal <no value> in output is a silently missing key, not an error.