How to Use Helm Template for Kubernetes Manifests
Use
helm template to render Kubernetes manifests from a Helm chart locally without installing them on a cluster. Run helm template [release-name] [chart-path] to output the generated YAML files to your terminal or save them for inspection.Syntax
The basic syntax of helm template is:
helm template [RELEASE_NAME] [CHART]: Renders templates with the given release name and chart path.--values, -f: Specify custom values files to override defaults.--output-dir: Save rendered manifests to a directory instead of printing.--namespace: Set the Kubernetes namespace in the rendered manifests.
bash
helm template [RELEASE_NAME] [CHART] [flags]
Example
This example shows how to render manifests from the official nginx Helm chart without installing it. It outputs the Kubernetes YAML to the terminal for review.
bash
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
helm template my-nginx bitnami/nginx --namespace webserverOutput
---
# Source: nginx/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
name: my-nginx
namespace: webserver
spec:
type: ClusterIP
ports:
- port: 80
targetPort: http
selector:
app.kubernetes.io/name: nginx
app.kubernetes.io/instance: my-nginx
---
# Source: nginx/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-nginx
namespace: webserver
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: nginx
app.kubernetes.io/instance: my-nginx
template:
metadata:
labels:
app.kubernetes.io/name: nginx
app.kubernetes.io/instance: my-nginx
spec:
containers:
- name: nginx
image: docker.io/bitnami/nginx:latest
ports:
- name: http
containerPort: 80
resources: {}
Common Pitfalls
- Not specifying a release name: Helm requires a release name to render templates correctly; omitting it can cause errors.
- Using
helm installinstead ofhelm template:helm installdeploys resources to the cluster, whilehelm templateonly renders manifests locally. - Ignoring values overrides: Forgetting to pass custom values files with
-fcan lead to unexpected default configurations. - Output confusion: Large output can be overwhelming; use
--output-dirto save files for easier inspection.
bash
## Wrong: Missing release name helm template bitnami/nginx ## Right: Include release name helm template my-nginx bitnami/nginx
Quick Reference
Here is a quick summary of useful helm template flags:
| Flag | Description |
|---|---|
| --values, -f | Specify values file to override defaults |
| --namespace | Set namespace in rendered manifests |
| --output-dir | Save rendered manifests to directory |
| --set | Set individual values on the command line |
| --show-only | Render only specified template files |
Key Takeaways
Use
helm template [release-name] [chart] to render manifests locally without deploying.Always specify a release name to avoid errors.
Use
-f or --set to customize values during rendering.Use
--output-dir to save output files for easier review.Remember
helm template does not install resources on the cluster.