Sub topic 3
Configuring a chart with values
This chapter assumes you know basic Kubernetes objects, can read YAML, and have a chart scaffolded with helm create webapp. You will see how a chart exposes settings through values and how users override them.
What values are
A chart's templates hold the structure of your manifests. Values hold the parts that change between installs, such as replica counts, image tags, and ports. Helm merges several sources into one .Values object and passes it to every template.
The chart's defaults live in values.yaml:
replicaCount: 2
image:
repository: nginx
tag: ""
pullPolicy: IfNotPresent
service:
type: ClusterIP
port: 80
env:
LOG_LEVEL: infoTemplates read these with dotted paths. {{ .Values.replicaCount }} renders 2, and {{ .Values.image.repository }} renders nginx. The empty tag is deliberate. The template falls back to .Chart.AppVersion when the tag is empty, so the default image follows the appVersion in Chart.yaml.
Where values come from
Helm builds the final values from several sources. Later sources win.
- The chart's own
values.yaml. - Files passed with
-for--values, in the order given. - Individual settings passed with
--set.
Maps are merged key by key. If your override file sets only image.tag, the other image keys keep their defaults.
Overriding values
Use a file for settings you want to keep in version control. Create prod.yaml:
replicaCount: 5
image:
tag: "1.27.1"
env:
LOG_LEVEL: warnThen render the chart with it and with one extra command-line override:
helm template my-release ./webapp -f prod.yaml --set replicaCount=3The result has 3 replicas, because --set beats the file. The image is nginx:1.27.1 and LOG_LEVEL is warn. The service block is unchanged.
--set uses dotted keys for nesting:
helm template my-release ./webapp --set image.tag=1.27.1 --set env.LOG_LEVEL=debugUse --set-string when a value must stay a string. Helm converts --set tag=1.10 to a number, which drops the trailing zero in some cases. Quoting inside a file avoids the same problem.
Common errors
- Lists are replaced, not merged. If you override a list, your list replaces the default entirely. Only maps merge.
- Type changes from
--set. Values such astrue,null, and123are converted to booleans, null, and integers. Use--set-stringwhen you want text. - Misspelled keys are silent. A typo like
replicacountcreates an unused value and the default stays in effect. Check the rendered output withhelm template. A schema, covered in a later chapter, catches this. - Nil pointer errors. Reading
.Values.image.tagwhenimageis missing fails withnil pointer evaluating interface {}. Keep defaults for every nested map invalues.yaml. - Commas in
--set. A comma separates settings, so--set a=b,cbreaks. Escape it as\,or move the value to a file.
Inspecting values
These commands show which values are in play:
helm show values ./webapp
helm get values my-release -n demo
helm get values my-release -n demo --allhelm show values prints the chart defaults. helm get values prints the overrides supplied to an installed release. Adding --all includes the defaults too.
Exercise
A chart's values.yaml sets replicaCount: 2. You run helm template r ./webapp -f prod.yaml --set replicaCount=3, and prod.yaml sets replicaCount: 5. How many replicas are rendered, and why?
Show answer
Three. Helm applies values.yaml first, then the -f files, then --set flags, and the later source wins. The --set value of 3 overrides the 5 from prod.yaml and the default 2.
Exercise
Your values.yaml has ports: [80, 443]. An override file contains ports: [8080]. What does the template see?
Show answer
It sees [8080]. Helm merges maps key by key but replaces lists wholesale, so the default list is discarded.