0
0
KubernetesHow-ToBeginner · 3 min read

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 webserver
Output
--- # 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 install instead of helm template: helm install deploys resources to the cluster, while helm template only renders manifests locally.
  • Ignoring values overrides: Forgetting to pass custom values files with -f can lead to unexpected default configurations.
  • Output confusion: Large output can be overwhelming; use --output-dir to 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:

FlagDescription
--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