docs / articles / Helm Template Range List

Helm Template Range List

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

In the realm of Kubernetes manifest manipulation, the Helm template range list is a powerful yet underutilized feature that allows for dynamic configuration and customization. This article delves into the intricacies of Helm's `range` function and its list syntax, empowering you to harness their potential in crafting robust and flexible Kubernetes deployments.

Templates — SKS PROPS
Templates — SKS PROPS

The need for dynamic configuration arises when faced with situations where you must reproducibility deploy Kubernetes resources with varying parameters. This could be due to scaling requirements, degrading conditions, or simply wanting to create multiple instances of a single resource. The Helm template range list is specifically designed to tackle such challenges, enabling you to loop through and customize configurations effortlessly.

the helmet and visor are shown in three different positions
the helmet and visor are shown in three different positions

Understanding Helm Template Ranges

Before diving into the list syntax, it's crucial to grasp the basics of the Helm `range` function. In essence, the `range` function iterates over a list, an object, or an array, executing a block of code for each element.

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

The primary syntax of the `range` function is as follows: ```yaml {{ range .Elements }} # Code block to be executed {{ end }} ``` Replace `.Elements` with the list, object, or array you want to iterate over.

Looping Through Lists

three different views of a motorcycle helmet
three different views of a motorcycle helmet

Looping through lists is the most common use case of the Helm `range` function. Consider a scenario where you need to deploy multiple instances of a single service, each with different labels. With the `range` function, you can loop through a list of labels and create a new instance for each:

```yaml {{ range $index, $label := .Labels }} - name: {{ .ServiceName }}-{{ $index }} labels: {{ $label }}: {{ $label.Value }} {{ end }} ```

In this example, `.ServiceName` would typically represent the base name of your service, while `.Labels` would be a list of label objects, each with a name and value.

The `range` function uses the `., $index, $value` convention for structurally typing arguments. Here, `$index` represents the current index of the loop, while `$label` stands for the current value being iterated over.

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

Looping Through Objects

The `range` function can also iterate over an object, treating its keys as the index and the corresponding values as the value. This approach is useful when you want to create or modify key-value pairs dynamically:

```yaml {{ range $key, $value := .Config }} - key: {{ $key }} value: {{ $value }} {{ end }} ```

In this case, `.Config` would ideally be an object containing your configuration settings. The loop will generate a new key-value pair for each entry in the configuration object.

an image of different types of helmets on a cell phone screen, with the caption's description below
an image of different types of helmets on a cell phone screen, with the caption's description below

Working with the Helm Template Range List Syntax

The list syntax for the Helm `range` function is a more compact and semantically expressive way of writing loops. It enables you to define lists inline and iterate over them without explicitly referencing a list variable:

a poster with different types of helmets on it
a poster with different types of helmets on it
three views of the front, back and side of a motorcycle helmet on a white background
three views of the front, back and side of a motorcycle helmet on a white background
Headgear Alignment Chart
Headgear Alignment Chart
Helmet Outline
Helmet Outline
the heinet base build template is shown in three different sizes, including one for each
the heinet base build template is shown in three different sizes, including one for each
История шлема. «Большие шлемы» приходят и уходят
История шлема. «Большие шлемы» приходят и уходят
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
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
Medieval Knight Armor Types, Ancient Military Helmets, Medieval Helmet Type, Type Of Helmets, Kinds Of Knight Helmets, Different Types Of Helmets, Knight Armor Name, Types Of Medieval Helmets, Medieval Helmets Design
Medieval Knight Armor Types, Ancient Military Helmets, Medieval Helmet Type, Type Of Helmets, Kinds Of Knight Helmets, Different Types Of Helmets, Knight Armor Name, Types Of Medieval Helmets, Medieval Helmets Design

The list syntax takes the form: ```yaml {{ range (list "value1" "value2" "value3") }} # Code block to be executed {{ end }} ```

In this example, the `range` function iterates over the list `["value1", "value2", "value3"]`, executing the code block for each value in the list.

Creating Configurable Lists

The Helm template range list syntax allows you to create configurable lists by combining it with other functions or global variables. This opens up the possibility of generating dynamic lists based on other variables or logic within your template:

```yaml {{ range (default .DefaultList .CustomList) }} # Code block to be executed {{ end }} ```

In this case, the `range` function uses the `default` function to first check if `.CustomList` is defined. If `true`, it uses `.CustomList`; if `false`, it falls back to `.DefaultList` for iteration.

You can also use functions such as `until` and `list $` in combination to create conditional lists or lists based on other elements in the template.

اللَّ o p s i n g О v е r О b j e c t s w i t h L i s t S y n t а x

The list syntax can also be used to loop over objects, treating their keys as the index and the corresponding values as the value. Moreover, it offers the flexibility of specifying a custom index and value alias, further simplifying your code.

```yaml {{ range (keys .Config) $key }} - key: {{ $key }} value: {{ index .Config $key }} {{ end }} ```

In this example, the `range` function iterates over the keys of the `.Config` object, generating a key-value pair for each config entry. The `index` function is then used to retrieve the value associated with the current key.

Embracing the Helm template range list and its syntax allows you to create dynamic, flexible, and maintainable Kubernetes deployments. By understanding the `range` function, lists, and objects, you're equipped to tackle a wide array of manifest manipulation challenges.

As you venture forth into the world of dynamic Kubernetes configurations, bear in mind that regular testing and refactoring are essential to keep your deployments robust and efficient. Keep exploring, keep learning, and keep your as partnerships secure and scalable!