Sub topic 9
Composing charts with dependencies
A chart can depend on other charts. This chapter assumes you can create a chart, edit values.yaml, and run helm install as covered in earlier chapters. You will declare a dependency, download it, and configure it from the parent chart.
Why use dependencies
An app often needs other services, such as a cache or a database. You can copy their manifests into your chart, or you can declare a dependency. A dependency, also called a subchart, is a complete chart that Helm installs together with your chart, the parent. The parent and its subcharts become a single release.
Declaring a dependency
List dependencies under dependencies in the parent's Chart.yaml:
dependencies:
- name: redis
version: "1.2.3"
repository: "https://charts.example.com"
condition: redis.enabledEach entry has these fields:
nameis the subchart's chart name.versionis an exact version or a range such as~1.2.0.repositoryis where Helm finds the chart. It can be an HTTPS URL, anoci://URL, or afile://path to a local chart.conditionis a values path that turns the dependency on or off.
Downloading dependencies
Declaring a dependency does not fetch it. Run this from the parent chart's directory:
helm dependency update ./webapp
helm dependency list ./webappupdate resolves each version, saves the archive in the charts/ directory, and writes Chart.lock. The lock file records the exact versions it chose. helm dependency build reads Chart.lock and downloads those same versions, so use it in CI for repeatable builds. Commit Chart.lock. Whether to commit the charts/*.tgz archives is a team choice, because you can always rebuild them.
Configuring a subchart
The parent sets a subchart's values under a key with the subchart's name. In the parent's values.yaml:
redis:
enabled: true
auth:
enabled: false
global:
environment: stagingHelm passes everything under redis: to the subchart as its own top-level values. From the command line, use the same path:
helm install my-release ./webapp --set redis.auth.enabled=trueValues flow only downward. A subchart cannot read the parent's values. The one exception is global. Everything under global is visible to the parent and to every subchart as .Values.global, which suits settings such as an environment name or an image registry.
The condition field works with these values. Setting redis.enabled=false skips the whole subchart. If the path is not set at all, the dependency stays enabled.
Useful options
aliasinstalls the same chart more than once under different names. The alias becomes the values key.tagsgroups several dependencies so onetags.<name>value switches them all.import-valuescopies chosen subchart values up into the parent.
Common errors
| Symptom | Cause | Fix |
|---|---|---|
| `found in Chart.yaml, but missing in charts/ directory` | The dependency was declared but never downloaded. | Run `helm dependency update`. |
| `the lock file (Chart.lock) is out of sync with the dependencies file` | `Chart.yaml` changed after the lock was written. | Run `helm dependency update` again. |
| A subchart ignores your override | The values key does not match the subchart name or alias. | Check `helm dependency list` and fix the key. |
| The parent's setting is not visible in a subchart | Values do not flow down unless they are under `global`. | Move the setting under `global`. |
Exercise
Your parent chart depends on a subchart named redis. Which command-line flag sets the subchart's replicaCount to 3, and how do you make it share an environment name with the parent?
Show answer
Use --set redis.replicaCount=3, because the parent addresses a subchart through a key with the subchart's name. For a shared setting, put it under global, for example --set global.environment=staging. Both the parent and the subchart can then read it as .Values.global.environment.