Skip to content
Tutorials Center
My learning

Topics

Lesson 20 of 38 ยท Dependencies and Hooks

Subchart Values and Global Values

Learn how parent values override subchart defaults, how the global key is shared with every subchart, and how scope works in templates, with a merge stand-in.

A subchart is a complete chart with its own values.yaml. When it sits inside a parent, you rarely want its defaults unchanged: you need a different password secret, fewer replicas, a smaller disk. Helm has a simple rule for this, plus one special key, global, for values every chart in the release should share.

The override rule

Values flow downward. The parent can set values for a subchart by putting them under a key that equals the subchart's name (or its alias). The subchart can never read the parent's values directly, with one exception: global.

Suppose the subchart redis ships this values.yaml:

YAML
architecture: standalone
auth:
  enabled: true
master:
  persistence:
    size: 8Gi

The parent's values.yaml overrides only what it cares about:

YAML
redis:
  master:
    persistence:
      size: 1Gi

Helm deep-merges the two. Keys not mentioned by the parent keep their defaults, so architecture stays standalone and auth.enabled stays true. Inside the subchart's templates, .Values.master.persistence.size is 1Gi: the redis: prefix is stripped, because from the subchart's point of view its own values are the root.

Command-line overrides use the same path:

Terminal
helm install shop ./shop --set redis.master.persistence.size=2Gi
helm install shop ./shop -f prod-values.yaml

Later sources win: chart defaults, then -f files in order, then --set. A subchart's defaults are always the weakest layer.

Python Stand-in: deep merge of parent and subchart values

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Global values

Sometimes one fact applies everywhere: the image registry mirror, the environment name, a storage class. Repeating it under every subchart name is error-prone. The reserved global key solves this:

YAML
global:
  imageRegistry: registry.internal.example.com
  environment: staging

Helm copies global into the values of every subchart (and into the parent). In any template at any depth:

YAML
image: {{ .Values.global.imageRegistry }}/{{ .Values.image.name }}

Rules worth remembering:

  • Globals flow down to all subcharts, even grandchildren.
  • A subchart cannot change a global for its parent. Values only travel downward.
  • A subchart can declare its own default under global:, but any value from the parent overrides it.
  • Good citizens use globals for cross-cutting settings only. Avoid putting application settings there, or every chart ends up reading everything.
Python Stand-in: propagating global values

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The stand-in shows the precedence: the parent's global.environment beats whatever the subchart wrote for itself.

Scope in templates

Inside a template, .Values always refers to the values of the chart that owns the template. A parent template that wants the subchart's setting must use the full path, .Values.redis.master.persistence.size. A subchart template that wants a parent's setting cannot: pass it through global or restructure so the subchart receives it under its own name.

Named templates (define) are a special case. They are shared across the whole release, so a template defined in a subchart is visible to the parent and the reverse. This is powerful, and risky: two charts defining mychart.fullname collide silently. Always prefix named templates with the chart name, a convention you will meet again in library charts.

Overriding a subchart's templates

You cannot edit a subchart's templates through values. If a value you need does not exist, you have three options:

  1. Open a pull request upstream to add the value.
  2. Unpack the subchart into charts/<name>/ and patch it (you now maintain a fork).
  3. Add your own extra objects in the parent's templates/ and leave the subchart alone. This is usually the cleanest choice.

Debugging what a subchart receives

To see the merged values the release will use:

Terminal
helm show values ./shop
helm template shop ./shop -f prod.yaml --show-only charts/redis/templates/master/statefulset.yaml
helm get values shop --all

helm get values --all includes computed defaults, which tells you whether your override reached the subchart.

A typo in the subchart key (Redis: instead of redis:) is silently ignored, because Helm treats it as an unrelated parent value. Use a JSON schema (see values schema validation) to catch this.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which key makes a value visible in every subchart?

    The reserved global key is copied into the values of all subcharts.
  2. 2. How are parent overrides combined with a subchart's defaults?

    Helm deep-merges maps, so unmentioned keys keep the subchart default.
  3. 3. Inside the redis subchart, how do templates read the parent's redis.auth.enabled value?

    The subchart sees its own section as the root of .Values.
  4. 4. Can a subchart change a global value for the parent chart?

    Parent values always take precedence and nothing flows back up.

Summary

  • Parent values under the subchart's name (or alias) deep-merge over its defaults.
  • Inside the subchart those values appear at the root of .Values.
  • global is the only way to share a value with all subcharts.
  • Named templates are release-wide, so prefix them with the chart name.

Next: Conditional Dependencies and import-values