Working with Subcharts

1. Adding Subcharts to Chart

MethodSteps
Declared dependencyAdd to Chart.yaml + helm dependency update
VendoredPlace chart directory directly under charts/

2. Declaring Subchart Dependencies

Example: Multiple subcharts

dependencies:
  - name: postgresql
    version: "15.3.0"
    repository: https://charts.bitnami.com/bitnami
    condition: postgresql.enabled
  - name: redis
    version: "19.0.0"
    repository: https://charts.bitnami.com/bitnami
    alias: cache

3. Overriding Subchart Values

Example: Override under subchart key

# Parent values.yaml
postgresql:        # must match subchart name (or alias)
  auth:
    username: api
    database: api_db
  primary:
    persistence:
      size: 20Gi
cache:             # uses alias
  master:
    persistence:
      size: 5Gi

4. Using Global Values

Example: Shared global block

# Parent values.yaml
global:
  imageRegistry: ghcr.io
  storageClass: fast-ssd
# Available as .Values.global.* in EVERY subchart automatically

5. Importing Subchart Values

Example: Surface subchart exports

dependencies:
  - name: postgresql
    version: "15.3.0"
    repository: https://charts.bitnami.com/bitnami
    import-values:
      - child: auth.username
        parent: db.user
      - exports.commonLabels   # short form (reads under exports:)

6. Conditionally Enabling Subcharts

FieldUsage
condition: postgresql.enabledSingle boolean
condition: a.enabled,b.enabledFirst found is used

7. Using Subchart Tags

Example: Group enable/disable

dependencies:
  - { name: postgresql, version: "15.3.0", repository: ..., tags: [stateful] }
  - { name: redis,      version: "19.0.0", repository: ..., tags: [stateful, cache] }
# values.yaml
tags:
  stateful: false   # disables both subcharts

8. Accessing Parent Values

Note: Subcharts CANNOT read parent values directly. Use global for shared config or import-values to pull data upward, not downward.

9. Sharing Templates Across Charts

ApproachHow
Library chartSet type: library; add as dependency; use include
Common helpersDefine helpers in parent's _helpers.tpl

10. Managing Subchart Versions

PracticeReason
Pin exact versionsReproducible deployments
Commit Chart.lockLock-file-driven CI builds
Test subchart upgradesRun in staging before bumping parent