docs / articles / Helm Template Range Over Map: Streamline Your Workflow

Helm Template Range Over Map: Streamline Your Workflow

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

When it comes to Helm, a popular package manager for Kubernetes, efficiently handling and manipulating data within your templates is crucial. One of the most powerful features enabling this is the `range over` clause, which allows for iteration over a list of values. Today, we're diving into the `helm template range over map`, exploring how this clause elevates your templating experience and simplifies complex scenarios.

Templates — SKS PROPS
Templates — SKS PROPS

Imagine you're creating a Kubernetes deployment with multiple replicas, each requiring a unique environment variable. Instead of manually creating and updating these variables one by one, you can leverage `range over map` to automate the process. Let's explore how this works.

an old map shows the location of helm's deep, which is located on top of a mountain
an old map shows the location of helm's deep, which is located on top of a mountain

Understanding `range over` and `map`

Before we dive into `range over map`, let's quickly recap `range over` and `map`.

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

`range over` is a Helm clause that iterates over a list of values, allowing you to generate dynamic content based on each item. It's particularly useful when you need to create multiple resources or repeating blocks of configuration.

Basic `range over` usage

the skmr 3 is shown in this diagram
the skmr 3 is shown in this diagram

Here's a simple example of `range over` generating pod replicas:

{{ range .Values.replicaCount }}
<!>> Pod definition goes here
</pre>

Now, let's understand `map` in the Helm context. A `map` is a key-value data structure, where each key maps to a value. In the world of YAML and Kubernetes, maps are often represented as dictionaries or associate arrays.

Basic `map` usage in Helm

Build an Iron Man Helmet for Cheap!
Build an Iron Man Helmet for Cheap!

Here's an example of accessing values from a `map`:

{{ .Values.myMap.key }}
</pre>

In this scenario, `myMap.key` would be replaced by the value associated with the key `key`.

`range over map`: Bridging the Gap

an old map with lines drawn on it
an old map with lines drawn on it

While `range over` and `map` are powerful on their own, combining them multiplies their might. With `range over map`, you can iterate over both the keys and values of a map simultaneously, unlocking new templating possibilities.

Let's revisit our environment variables use case. Instead of defining a list of variables, we'll use a `map` to store each variable's name and value. Then, `range over map` will iterate through this map, generating unique environment variables for each replica.

a drawing of a compass on top of a map
a drawing of a compass on top of a map
Résultats Google Recherche d'images correspondant à https://thumbs.dreamstime.com/b/d-illustration-conquistador-morion-helmet-isolated-different-backgrounds-170847159.jpg
Résultats Google Recherche d'images correspondant à https://thumbs.dreamstime.com/b/d-illustration-conquistador-morion-helmet-isolated-different-backgrounds-170847159.jpg
a black and white compass with the word w e on it's center circle
a black and white compass with the word w e on it's center circle
Helm and navigation map stock image. Image of nautics - 15194345
Helm and navigation map stock image. Image of nautics - 15194345
several pieces of paper with writing on them
several pieces of paper with writing on them
Anchor and helm sketches, vintage antique map
Anchor and helm sketches, vintage antique map
Get Dressed For Battle
Get Dressed For Battle
Helm & Navigation Card reference.
Helm & Navigation Card reference.

Implementing `range over map`

Here's a basic example of `range over map` generating environment variables:

{{ range $key, $value := .Values.envVars }}
<-- Environment variable definition goes here using $key and $value -->
</pre>

With this structure, you can dynamically create environment variables based on the `envVars` map. The `$key` represents the variable's name, and `$value` represents its value.

Mixing `range over map` with conditional logic

To make things even more interesting, you can mix `range over map` with Helm's conditional statements like `if` and `with`. Here's an example that generates environment variables only if they exist:

{{ range $key, $value := .Values.envVars }}
  <!-- Generate environment variable only if the value exists -->
  {{ if $value }}
<!-- Environment variable definition goes here using $key and $value -->
  {{ end }}
</pre>

Now, you can create cleaner, more maintainable templates that dynamically adapt to your application's needs.

Mastering `helm template range over map` means you've gained a powerful weapon in your Kubernetes templating arsenal. As you embark on your template-writing journey, remember that there's no substitute for practical experience. So, start small, experiment with `range over map`, and watch as your templates come to life!