Values Files & Overrides
Values are the chart's public interface. Users never edit templates; they write a values file per environment and pass a few --set flags in CI. Getting the merge rules right is what makes one chart serve every environment.
Where values come from
From lowest to highest precedence:
- the chart's
values.yaml; - a parent chart's
values.yaml, for subcharts (see Chart Dependencies); - each
-f/--valuesfile, in the order given (later files win); --set,--set-string,--set-json,--set-file,--set-literal, in order.
Maps are deep-merged key by key. Everything else, including lists, is replaced as a whole. A key set to null is deleted, which is how you remove a default.
A chart with three environments
mkdir -p linkly/templates && cd linkly
printf 'apiVersion: v2\nname: linkly\nversion: 0.3.0\n' > Chart.yaml
cat > values.yaml <<'EOF'
replicaCount: 2
image:
repository: ghcr.io/acme/linkly
tag: "1.4.0"
env:
LOG_LEVEL: info
REDIS_ADDR: linkly-redis:6379
resources:
requests: {cpu: 100m, memory: 64Mi}
limits: {memory: 128Mi}
hostnames: [lnk.example.com]
EOF
cat > values-staging.yaml <<'EOF'
replicaCount: 1
env:
LOG_LEVEL: debug
hostnames: [lnk.staging.example.com]
EOF
cat > values-prod.yaml <<'EOF'
replicaCount: 5
resources:
requests: {cpu: 250m, memory: 128Mi}
limits: {memory: 256Mi}
EOF
printf '{{ toYaml .Values }}\n' > templates/values.yaml
echo "=== staging"; helm template s . -f values-staging.yaml | tail -n +3
echo "=== prod, tag from CI"; helm template p . -f values-prod.yaml --set image.tag=1.4.1 | yq '{"replicas": .replicaCount, "image": .image.tag, "requests": .resources.requests}'=== staging
env:
LOG_LEVEL: debug
REDIS_ADDR: linkly-redis:6379
hostnames:
- lnk.staging.example.com
image:
repository: ghcr.io/acme/linkly
tag: 1.4.0
replicaCount: 1
resources:
limits:
memory: 128Mi
requests:
cpu: 100m
memory: 64Mi
=== prod, tag from CI
replicas: 5
image: 1.4.1
requests:
cpu: 250m
memory: 128Mi
Staging kept REDIS_ADDR from the defaults while overriding LOG_LEVEL (maps merge), but hostnames was replaced, not appended to (lists don't). Production overrode both resource maps and took its image tag from --set, which is how a CI pipeline injects the version it just built.
Tip:
printf '{{ toYaml .Values }}\n' > templates/values.yamlis a handy debugging trick: a throwaway template that prints the final merged values. Delete it before you commit.
The --set family
--set has its own mini-syntax, and its type guessing is the source of many surprises:
mkdir -p c/templates && cd c
printf 'apiVersion: v2\nname: c\nversion: 0.1.0\n' > Chart.yaml
cat > values.yaml <<'EOF'
podAnnotations: {}
extraArgs: []
limits: {cpu: 500m, memory: 128Mi}
EOF
printf '{{ toYaml .Values }}\n' > templates/values.yaml
echo "token: s3cr3t-from-a-file" > token.txt
helm template d . \
--set 'podAnnotations.prometheus\.io/port=9090' \
--set 'extraArgs={--verbose,--color=never}' \
--set limits.cpu=null \
--set featureFlag=true \
--set podLabels.canary=true \
--set-string podAnnotations.canary=true \
--set version=1.10 \
--set-json 'tolerations=[{"key":"spot","operator":"Exists"}]' \
--set-literal 'motd=a,b=c' \
--set-file license=token.txt | tail -n +3extraArgs:
- --verbose
- --color=never
featureFlag: true
license: |
token: s3cr3t-from-a-file
limits:
memory: 128Mi
motd: a,b=c
podAnnotations:
canary: "true"
prometheus.io/port: 9090
podLabels:
canary: true
tolerations:
- key: spot
operator: Exists
version: "1.10"
| Form | Use it for |
|---|---|
--set a.b=c |
simple scalars; dots descend into maps |
--set 'a\.b=c' |
a key that contains dots (annotation and label names) |
--set 'l={x,y}', --set 'l[0].name=x' |
lists, or one field of a list element |
--set k=null |
delete a key (here the CPU limit) |
--set-string k=true |
force a string; plain --set turns true/false into booleans, whole numbers into integers and null into a deletion |
--set-json |
structured values without escaping commas |
--set-literal |
a string with commas or = taken literally |
--set-file |
the content of a file (certificates, scripts) |
Look at podLabels.canary and featureFlag: --set guessed that true is a boolean, so the label value would be rejected by the API server (label and annotation values must be strings), while --set-string kept the annotation a string. The same happened to prometheus.io/port: it became the integer 9090, and a template that copies annotations with toYaml would produce an invalid annotation. version=1.10 stayed a string because --set only converts integers, booleans and null; in a values file, unquoted 1.10 would become the number 1.1, so quote versions there. When more than one or two --set flags appear in a pipeline, write a values file instead; it can be reviewed and diffed.
Helm 4: several documents in one values file
Helm 4 accepts a values file with several YAML documents separated by ---, merged top to bottom as if they were separate -f files. It lets you keep, for example, a generated block and hand-written overrides in one file:
mkdir -p c/templates && cd c
printf 'apiVersion: v2\nname: c\nversion: 0.1.0\n' > Chart.yaml
printf 'replicaCount: 2\nimage: {tag: "1.4.0"}\n' > values.yaml
printf '{{ toYaml .Values }}\n' > templates/values.yaml
cat > prod.yaml <<'EOF'
# generated by the release pipeline
image: {tag: "1.4.1"}
---
# hand-written
replicaCount: 5
EOF
helm template d . -f prod.yaml | tail -n +3image:
tag: 1.4.1
replicaCount: 5
Helm 3 reads only the first document of a values file and silently ignores the rest, so don't use this in charts or pipelines that must still work with Helm 3.
A YAML trap in values files
YAML 1.1, which Helm's parser follows for unquoted scalars, treats y, n, yes, no, on and off as booleans. Even a key named y becomes "true":
mkdir -p c/templates && cd c
printf 'apiVersion: v2\nname: c\nversion: 0.1.0\n' > Chart.yaml
cat > values.yaml <<'EOF'
position: {x: 10, y: 20}
country: NO
quoted: "NO"
EOF
printf '{{ toYaml .Values }}\n' > templates/values.yaml
helm template d . | tail -n +3country: false
position:
"true": 20
x: 10
quoted: "NO"
Norway's country code became false and the y key became "true". Quote strings that look like booleans or numbers, in values files and in templates.
Inspecting values
helm show values <chart>prints a chart's defaults, from a directory, a.tgzor a registry; read it before installing anything.helm get values <release>prints what a user supplied for an installed release; add--allfor the fully merged set. On upgrade,--reuse-valueskeeps the last release's user values,--reset-valuesgoes back to the chart's defaults, and--reset-then-reuse-valuestakes the new chart's defaults plus the old user values, usually what you want when a chart upgrade adds keys.
The Kubernetes Helm lesson has a Python model of the deep merge if you want to see the algorithm itself.
Test yourself
values.yaml has hostnames: [a, b]; -f prod.yaml has hostnames: [c]. What is rendered?
- [a, b, c]
- [c]
- [a, b]
- an error
How do you remove resources.limits.cpu that the chart sets by default?
- --set resources.limits.cpu=""
- --set resources.limits.cpu=null
- --unset resources.limits.cpu
- You can't
--set podLabels.canary=true makes the API server reject the Pod. What is the fix?
- --set podLabels.canary='true'
- --set-string podLabels.canary=true
- --set-json podLabels.canary=true
- --set podLabels.canary=yes