Helm Functions
Template Functions and Pipelines
๐งญ Helm Template Functions Cheat Sheet with Examples
This document provides a comprehensive list of Helm template functions used in Helm charts, with real-world examples using .Values, .Chart, and .Release.
๐ง Commonly Used Functions
๐๏ธ default โ Provide a fallback value
replicaCount: {{ .Values.replicaCount | default 3 }}If
.Values.replicaCountis not set invalues.yaml, it defaults to3.
โ required โ Make a value mandatory
apiVersion: v1
kind: Secret
metadata:
name: my-secret
data:
password: {{ required "A password is required!" .Values.password | b64enc }}apiVersion: v1
kind: Secret
metadata:
name: my-secret
data:
{{- if .Values.password }}
password: {{ .Values.password | b64enc | quote }}
{{- else }}
password: ""
{{- end }}Will throw an error at install/upgrade if
passwordis not provided.
How to render yaml files from new charts
helm template my-nginx01 ./nginx-demo -n helm-test --debug๐ค String Functions
upper, lower, title, trim, replace
metadata:
name: {{ .Chart.Name | upper }}-{{ .Release.Name | lower }}
annotations:
summary: {{ .Values.summary | title | quote }}Transforms strings:
helmโHELMrelease-nameโrelease-namesome textโSome Text
annotations:
clean-name: {{ replace .Chart.Name "-" "_" }}Replaces hyphens (
-) with underscores (_) in the chart name.
Useful for making label-safe names.
๐ข Number Functions
add, sub, mul, div, mod
resources:
limits:
cpu: {{ mul .Values.cpuBase .Values.cpuFactor }}replicaCount: {{ add 2 3 }} # Output: 5Perform arithmetic using Helm values.
๐ List Functions
list, join, first, last, uniq, range
โ
Example: Looping with range and list
env:
{{- range $env := list "STAGING" "PROD" "DEV" }}
- name: ENV
value: {{ $env }}
{{- end }}Loops over the list and renders each value as an environment variable.
Rendered output:
env:
- name: ENV
value: STAGING
- name: ENV
value: PROD
- name: ENV
value: DEVโ
Example: join โ Convert a list to comma-separated string
labels:
environments: {{ join "," (list "dev" "staging" "prod") }}Converts list to string:
dev,staging,prod.
โ
Example: uniq โ Remove duplicates from list
uniq-values: {{ uniq (list 1 2 2 3 1) }} # Output: [1 2 3]Removes duplicate values.
Usejoinif you need to convert it to string for use in annotations/labels.
๐๏ธ Dictionary/Object Functions
dict, hasKey, pluck, keys
{{- $config := dict "env" "prod" "region" "us-west" }}
region: {{ $config.region }}{{- if hasKey .Values "replicaCount" }}
replicas: {{ .Values.replicaCount }}
{{- end }}These functions help dynamically access and iterate through key-value pairs.
๐ Flow Control
if, else, range, with
{{- if .Values.enabled }}
metadata:
labels:
enabled: "true"
{{- else }}
metadata:
labels:
enabled: "false"
{{- end }}{{- range $key, $val := .Values.config }}
{{ $key }}: {{ $val }}
{{- end }}in Values.yaml
config:
timeout: 30s
retries: 5
logLevel: debug{{- with .Values.database }}
host: {{ .host }}
port: {{ .port }}
{{- end }}in Values.yaml
database:
host: db.example.com
port: 5432Conditional logic and scoping for clean, DRY templates.
๐ Crypto & Encoding
b64enc, b64dec, sha256sum
data:
password: {{ .Values.dbPassword | b64enc }}hashed: {{ "sensitive" | sha256sum }}Useful for secrets, hashing, and safe encoding.
๐ Date & Time (Limited)
annotations:
generatedAt: {{ now | date "2006-01-02T15:04:05Z07:00" }}
nowreturns current timestamp.
Format it using Go time layout (2006-01-02is the reference format).
๐งช Example values.yaml
replicaCount: 2
enabled: true
summary: "simple chart"
cpuBase: 100
cpuFactor: 2
password: "secret123"
dbPassword: "admin"
envList:
- name: ENV
value: PROD
config:
LOG_LEVEL: debug
TIMEOUT: 30
database:
host: db.example.com
port: 5432
services:
service1:
port: 80
service2:
port: 443