TExcelTAD
Home › Kubernetes Packaging: Helm & Kustomize › Chart Dependencies

Chart Dependencies

A chart can include other charts, called subcharts or dependencies. linkly needs a Redis cache in development and preview environments; instead of copying a Redis Deployment into linkly's templates, the chart depends on a separate cache chart and switches it on or off per environment.

Note: Public examples usually reach for a Bitnami chart here. Bitnami moved most of its free charts and images to an unmaintained legacy repository in 2025, so this course uses its own small charts from a local OCI registry. The mechanics are identical for any chart source.

Declaring dependencies

Dependencies are listed in Chart.yaml:

yaml
dependencies:
  - name: cache                          # the subchart's name
    version: ~1.2.0                      # a SemVer range: >=1.2.0 <1.3.0
    repository: oci://localhost:5000/charts   # or https://…, or file://../cache
    condition: cache.enabled             # a values path that switches it on/off
    alias: sessions                      # optional: install it under another name
    tags: [backing-services]             # optional: switch groups on/off
    import-values: [...]                 # optional: pull values up from the child

helm dependency update resolves each range, downloads the chart into charts/ and writes Chart.lock with the exact versions and a digest. helm dependency build downloads exactly what Chart.lock says, which is what CI should run. Commit Chart.lock; whether you commit charts/*.tgz is a team choice (most don't).

A dependency from an OCI registry

The session publishes a cache chart to the local registry, then makes linkly depend on it. A subchart reads its own values from the parent's values under its name (cache:), and global: values are visible to every chart:

bash · try it yourself
mkdir -p cache/templates linkly/templates
printf 'apiVersion: v2\nname: cache\nversion: 1.2.0\nappVersion: "8.2"\n' > cache/Chart.yaml
printf 'maxmemory: 64mb\n' > cache/values.yaml
cat > cache/templates/configmap.yaml <<'EOF'
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-{{ .Chart.Name }}
data:
  maxmemory: {{ .Values.maxmemory | quote }}
  environment: {{ .Values.global.environment | default "unset" | quote }}
EOF
helm package cache >/dev/null && helm push cache-1.2.0.tgz oci://localhost:5000/charts --plain-http 2>&1 | head -1
cat > linkly/Chart.yaml <<'EOF'
apiVersion: v2
name: linkly
version: 0.6.0
dependencies:
  - name: cache
    version: ~1.2.0
    repository: oci://localhost:5000/charts
    condition: cache.enabled
EOF
cat > linkly/values.yaml <<'EOF'
global:
  environment: staging
cache:
  enabled: true
  maxmemory: 256mb
EOF
helm dependency update linkly --plain-http
helm dependency list linkly
grep -v generated linkly/Chart.lock
echo "--- rendered"
helm template web linkly | tail -n +3
echo "--- cache disabled:"
helm template web linkly --set cache.enabled=false | grep -c '^kind:'
Pushed: localhost:5000/charts/cache:1.2.0
Saving 1 charts
Downloading cache from repo oci://localhost:5000/charts
Pulled: localhost:5000/charts/cache:1.2.0
Digest: sha256:2fcbb27b0265e92c0079f7cce09c9f5168dc28b733644b3caba5983d7373ba90
Deleting outdated charts
NAME 	VERSION	REPOSITORY                 	STATUS
cache	~1.2.0 	oci://localhost:5000/charts	ok

dependencies:
- name: cache
  repository: oci://localhost:5000/charts
  version: 1.2.0
digest: sha256:678d7f850298053c285c3f6940e4fa8a7b292b7783091e23e08470cce79bedb1
--- rendered
apiVersion: v1
kind: ConfigMap
metadata:
  name: web-cache
data:
  maxmemory: "256mb"
  environment: "staging"
--- cache disabled:
0
  • The parent's cache.maxmemory: 256mb overrode the subchart's default 64mb: a parent can override anything in a child, but a child can never see the parent's values except global.
  • condition: cache.enabled removed the whole subchart when false. Note that enabled itself is passed down to the subchart, harmlessly.
  • Chart.lock pins 1.2.0 exactly, though the range allowed any 1.2.x. Its generated: line is a timestamp, filtered out above.

Aliases: the same chart twice

alias installs a dependency under another name, so one chart can appear more than once. Here two caches with different sizes, from a file:// dependency (useful in a monorepo and for development):

bash · try it yourself
mkdir -p cache/templates linkly/templates
printf 'apiVersion: v2\nname: cache\nversion: 1.2.0\n' > cache/Chart.yaml
printf 'maxmemory: 64mb\n' > cache/values.yaml
cat > cache/templates/configmap.yaml <<'EOF'
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-{{ .Chart.Name }}
data:
  maxmemory: {{ .Values.maxmemory | quote }}
EOF
cat > linkly/Chart.yaml <<'EOF'
apiVersion: v2
name: linkly
version: 0.6.0
dependencies:
  - name: cache
    alias: links-cache
    version: 1.2.0
    repository: file://../cache
  - name: cache
    alias: rate-limiter
    version: 1.2.0
    repository: file://../cache
    tags: [optional]
EOF
cat > linkly/values.yaml <<'EOF'
links-cache:
  maxmemory: 512mb
tags:
  optional: true
EOF
helm dependency build linkly >/dev/null
helm template web linkly | grep -E 'name:|maxmemory'
echo "--- optional tag off:"
helm template web linkly --set tags.optional=false | grep -E 'name:'
  name: web-links-cache
  maxmemory: "512mb"
  name: web-rate-limiter
  maxmemory: "64mb"
--- optional tag off:
  name: web-links-cache

Each alias gets its own values key and .Chart.Name. Tags switch groups of dependencies at once (tags.optional=false); a condition on a dependency takes precedence over its tags.

Passing values between parent and child

Direction Mechanism
parent → child values under the child's name or alias: cache: {maxmemory: 256mb}
parent → all children global: values, read as .Values.global.x everywhere
child → parent import-values in the dependency entry, which copies values the child exports into the parent's values

Named templates go both ways automatically, because all templates of a chart and its subcharts share one namespace. That's why helpers must be prefixed with the chart's name.

Subcharts or separate releases?

A subchart is installed, upgraded and rolled back with the parent, in the same release and namespace. That suits small companions (a cache for a preview environment, a library chart). Stateful services with their own lifecycle, such as a production database, are better as separate releases or managed services: you don't want a linkly rollback to roll back PostgreSQL. In production, linkly uses a managed database and turns cache.enabled off in favour of a shared Redis.

Test yourself

What should CI run to get exactly the dependency versions the team tested?

  1. helm dependency update
  2. helm dependency build
  3. helm repo update
  4. helm pull --latest

How does a subchart named cache receive maxmemory: 256mb from its parent?

  1. Under the parent's cache: key
  2. Under global: only
  3. Via --set-subchart
  4. It can't

Why do aliases exist?

  1. To rename a chart permanently
  2. To include the same chart more than once, each with its own values
  3. To pin a version
  4. To switch to OCI