Working with Template Functions
1. Accessing Values ({{ .Values.key }})
Expression Result
{{ .Values.replicaCount }}Top-level scalar
{{ .Values.image.repository }}Nested field
{{ index .Values "weird-key" }}Key with dashes/dots
{{ .Values.missing | default "x" }}Safe access with fallback
2. Using Pipeline Operations
name : {{ .Values.appName | lower | trunc 63 | trimSuffix "-" | quote }}
3. Quoting Strings
Function Output
quoteWraps in double quotes
squoteWraps in single quotes
printf "%q" .Go-style quoted string
4. Converting to YAML
Example: Render arbitrary structure
nodeSelector :
{{- toYaml .Values.nodeSelector | nindent 2 }}
tolerations :
{{- toYaml .Values.tolerations | nindent 2 }}
5. Converting to JSON
Function Use
toJsonCompact JSON
toPrettyJsonIndented JSON
fromJsonParse JSON string into map
6. Using Default Values
Example: Fallback chain
tag : {{ .Values.image.tag | default .Chart.AppVersion | quote }}
host : {{ .Values.host | default "localhost" }}
port : {{ .Values.port | default 8080 }}
7. String Manipulation
Function Effect
upper / lower / titleCase conversion
trim / trimAll / trimPrefix / trimSuffixStrip whitespace/chars
trunc NLimit to N characters
replace "a" "b" .String replace
contains "sub" .Boolean substring check
split "/" .Returns dict _0, _1...
splitList "/" .Returns true list
printf "%s-%d" .Name 1Formatted string
8. Type Conversion
Function Converts to
toStringString
int / int64 / atoiInteger
float64Float
toJson / fromJsonJSON
toYaml / fromYamlYAML
typeOf .Reflect type name
kindOf .Underlying kind (string, map, slice...)
9. Encoding Functions
Function Use
b64enc / b64decBase64
b32enc / b32decBase32
sha1sum / sha256sumHashing (for checksum annotations)
adler32sumAdler-32 checksum
10. Date Functions
Function Result
nowCurrent time.Time
date "2006-01-02" nowFormat using Go reference time
dateInZone "2006-01-02T15:04:05Z" now "UTC"Zone-aware format
htmlDate / htmlDateInZoneHTML5 date format
Warning: now changes on every render — it forces rolling updates if used in annotations. Use .Release.Time if you want stability across re-renders.
11. UUID Generation
Example: Random UUID v4
annotations :
rollout-id : {{ uuidv4 | quote }}
Warning: uuidv4 changes per render — triggers unnecessary pod restarts. Prefer hashing values for stability.
12. Using fail Function
Example: Hard validation
{{- if not .Values.image.repository }}
{{- fail "image.repository is required" }}
{{- end }}
{{- if and .Values.persistence.enabled (not .Values.persistence.size) }}
{{- fail "persistence.size required when persistence.enabled=true" }}
{{- end }}
Function Behavior
fail "msg"Aborts render with error message
required "msg" .Values.xAborts if value is nil/empty