Helm template variables
In addition to leveraging values and other built-in objects, chart developers can create variables of their own within chart templates to provide additional processing options. A common use case for this approach is flow control, but template variables can serve other use cases as well.
A variable in a chart template is defined as follows:
{{ $myvar := "Hello World!" }}
The preceding example creates a variable called myvar
and sets the value to a string equaling to Hello World!
. Variables can be assigned to objects as well, such as a chart’s values, as illustrated here:
{{ $myvar := .Values.greeting }}
Once a variable is defined, it can be referenced in the following way:
data: greeting.txt: |- {{ $myvar }}
Another example of using variables is in a range
block, where variables capture the index and value of list iterations, as illustrated in the following code snippet:
data: ...