docs / articles / Helm Template Example Command

Helm Template Example Command

Noah Aug 16, 2026 2026-08-16 04:58:21

The power of infrastructure as code (IaC) lies in its ability to automate, version control, and store your provisioning logic alongside your codebase. Helm, a package manager for Kubernetes, extends this capability by managing and deploying your Kubernetes applications. It uses a plaintext configuration file format known as Kubernetes YAML, making it easy to understand and use. One of the key features of Helm is its ability to generate ready-to-deploy Kubernetes manifests from templates. This allows you to define complex application configurations once, параметры which can then be instantiated and customized for different environments. Let's delve into a practical Helm template example command to illustrate this concept.

Templates — SKS PROPS
Templates — SKS PROPS

Helm templates are written using the Go templating language, which is a simple yet powerful syntax for generating dynamic text. They are stored in the templates directory of your Helm chart and follow the same structure as your desired Kubernetes manifests. When you run a Helm command, like helm install or helm upgrade, Helm renders these templates using the values provided in the values.yaml file or passed as command-line arguments. It then generates the corresponding Kubernetes manifests, which it passes to Kubernetes for deployment.

an image of a helmet with measurements and instructions for the parts to be used in this project
an image of a helmet with measurements and instructions for the parts to be used in this project

Understanding Helm Templates

To get started with Helm templates, it's essential to understand their basic structure and components. Helm templates consist of a set of replaceable placeholders, called go-templates, which are enclosed in double curly braces ({{...}}) or pipes (|...). These placeholders are replaced with the actual values during the rendering process. Additionally, Helm templates can include functions to perform various tasks like concatenating strings, creating lists, and even complex operations like looping through data.

Firefighter Helmet Shield Silhouette Images – Browse 920 Stock Photos, Vectors, and Video
Firefighter Helmet Shield Silhouette Images – Browse 920 Stock Photos, Vectors, and Video

Let's explore a simple Helm template example to shed light on these concepts. Consider the following hypothetical templates/deployment.yaml: ```yaml apiVersion: apps/v1 kind: Deployment metadata: name: {{ .Release.Name }} labels: app: {{ .Values.app.label }} spec: replicas: {{ .Values.replicas }} selector: matchLabels: app: {{ .Values.app.label }} template: metadata: labels: app: {{ .Values.app.label }} spec: containers: - name: {{ .Chart.Name }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" ports: - containerPort: {{ .Values.containerPort }} ``` In this example, `.Release.Name`, `.Values.app.label`, `.Values.replicas`, `.Values.image.repository`, `.Values.image.tag`, and `.Values.containerPort` are all placeholders that will be replaced with actual values when the template is rendered.

Using Default Values

Drawing of a knight's helmet
Drawing of a knight's helmet

Helm allows you to set default values for your templates in the values.yaml file of your chart. This file is a simple YAML document that contains the default values for your chart. When you install or upgrade your chart, you can override these values using command-line arguments or a custom values.yaml file. Here's an example of what a values.yaml file might look like: ```yaml app: label: my-app replicas: 3 image: repository: nginx tag: latest containerPort: 80 ``` In this case, if you don't provide any values when installing the chart, Helm will use these default values to render the templates.

You can also override these default values when running a Helm command. For instance, the following command will override the replicas and containerPort values: ```bash helm install my-release --set replicas=5 --set image.tag=v1.16.2 --set containerPort=8080 ./mypath/templates ```

Including Functions in Helm Templates

HELM Logo
HELM Logo

Helm templates support various built-in functions that you can use to manipulate values. These functions allow you to perform operations like concatenating strings, creating lists, and even complex operations like looping through data. For example, consider the following hypothetical templates/ service.yaml: ```yaml apiVersion: v1 kind: Service metadata: name: {{ .Release.Name }}-service spec: selector: app: {{ .Values.app.label }} ports: - protocol: TCP port: {{ .Values.service.port }} targetPort: {{ .Values.containerPort }} ``` In this example, the service.port value is derived from the containerPort value. You can achieve this by using the add function, like so: {{ .Values.containerPort | add 1 }}. This will add 1 to the value of containerPort.

Another useful function is range, which allows you to loop through a list of values. This can be particularly useful if you want to generate multiple resources based on a list of items. For instance, if you had a list of ports to expose in your values.yaml file: ```yaml ports: - name: http containerPort: 80 - name: https containerPort: 443 ``` You could use the range function to generate a Service for each port: ```yaml {{- range .Values.ports }} - protocol: TCP port: {{ .containerPort }} targetPort: {{ .containerPort }} {{- end }} ``` In this example, the {{- range .Values.ports }} statement starts a loop that iterates through each item in the ports list. The {{- end }} statement marks the end of the loop. Within the loop, each item is referred to as ., so {{ .containerPort }} retrieves the containerPort value for the current item in the loop.

Rendering Helm Templates

Helm: Render Chart Templates Locally
Helm: Render Chart Templates Locally

Now that we've covered the basics of Helm templates let's look at how to render them. Rendering a Helm template involves providing it with the necessary values and then executing the template code to generate the resulting manifest. Helm provides several commands for rendering templates, including helm template and helm get values. The helm template command is typically used to generate Kubernetes manifests locally, which can then be applied using kubectl. The helm get values command is used to retrieve the current values for a deployed release.

To render templates locally, you can use the following helm template command: ```bash helm template my-release ./mypath/templates -f ./mypath/values.yaml ``` In this command, my-release is the name of the release, ./mypath/templates specifies the path to the templates directory, and -f ./mypath/values.yaml specifies the path to the values.yaml file containing the default values. The output of this command will be a set of Kubernetes manifests, one for each template.

a drawing of a boat and its parts are shown in the diagram, with measurements for it
a drawing of a boat and its parts are shown in the diagram, with measurements for it
Master Chief Helm - Scott Bowman
Master Chief Helm - Scott Bowman
the diagram shows how to cut and sew with scissors, which are also used for sewing
the diagram shows how to cut and sew with scissors, which are also used for sewing
Viking Helmet Template – Medium
Viking Helmet Template – Medium
paper cut out of different shapes and sizes, including the top one with torn edges
paper cut out of different shapes and sizes, including the top one with torn edges
[WIP] Warhammer 40k Space Marine Helmet
[WIP] Warhammer 40k Space Marine Helmet
Printable Roman Helmets
Printable Roman Helmets

The helm get values command can be used to retrieve the current values for a deployed release. For example: ```bash helm get values my-release ``` This command retrieves the current values for the my-release deployment and displays them in YAML format.

Using Values to Customize Deployments

As mentioned earlier, Helm uses values to customize deployments. You can provide values in several ways: by defining them in a values.yaml file, providing them on the command line, or using a combination of both. For instance, you can pass a values.yaml file as an argument when installing a chart: ```bash helm install my-release ./mypath/charts/mychart -f ./mypath/values.yaml ``` You can also provide values using the --set flag. For example: ```bash helm install my-release ./mypath/charts/mychart --set replicas=5 --set app.label=my-app ``` In this command, the my-app value will override the default value of app.label, and the deployment will be created with 5 replicas.

Helm also supports creating and using custom values files. This is particularly useful when you want to maintain different sets of values for different environments, like development, staging, and production. You can use the helm install command with the --values flag to apply a custom values file: ```bash helm install my-release ./mypath/charts/mychart -f ./mypath/staging-values.yaml ``` In this command, staging-values.yaml is the custom values file for the staging environment.

Leveraging Helm Hooks for Complex Deployments

In some cases, you may need to perform additional steps to fully deploy an application, such as creating a database or running a script. Helm hooks allow you to run arbitrary hook scripts before or after installing, upgrading, or removing a release. Hooks can be used to run commands, create Kubernetes resources, or even call other Helm charts during the deployment process.

To use hooks in your chart, you need to create a hooks directory in the root of your chart. Each hook is a script or executable that performs the necessary actions. You can define hooks to run at any of the following stages: - pre-install: Run before a release is installed. - post-install: Run after a release is installed. - pre-upgrade: Run before a release is upgraded. - post-upgrade: Run after a release is upgraded. - pre-rollback: Run before a release is rolled back to a previous version. - post-rollback: Run after a release is rolled back to a previous version. - pre-delete: Run before a release is deleted. - post-delete: Run after a release is deleted. You can create scripts for these hooks and place them in the appropriate subdirectories of the hooks directory. For example, if you wanted to create a post-install hook script to create a Kubernetes secret, you would create a hooks/post-install directory and place your script inside it. Helm will automatically detect these hooks and run them at the appropriate times during the deployment process.

Exploring Helm templates and commands can seem daunting at first, but with practice and a solid understanding of the fundamentals, you'll find that it's a powerful tool for managing and deploying Kubernetes applications. Whether you're a developer looking to streamline your deployment workflow or an operations professional seeking to automate your infrastructure, Helm provides a robust set of features to meet your needs. Now that you have a solid foundation in Helm templates and commands, you're ready to dive in and start using Helm in your projects.