Dependencies & Subcharts

๐Ÿ”ฅ Vibe Prompt

"Helm chart with Postgres (subchart), Redis (subchart), and my app. Override subchart values."

Chart.yaml with Dependencies

apiVersion: v2
name: fullstack
version: 1.0.0
dependencies:
  - name: postgresql
    version: "12.x"
    repository: https://charts.bitnami.com/bitnami
    condition: postgresql.enabled
  - name: redis
    version: "18.x"
    repository: https://charts.bitnami.com/bitnami
    condition: redis.enabled
# Download dependencies
helm dependency update ./fullstack
# This creates charts/postgresql-12.x.tgz

Override Subchart Values

# values.yaml
postgresql:
  enabled: true
  auth:
    database: myapp
    username: myuser
    password: securepass
  primary:
    resources:
      limits:
        memory: "1Gi"

redis:
  enabled: true
  architecture: standalone
  auth:
    enabled: true
    password: redispass

Global Values

# Shared across all charts
global:
  environment: production
  monitoring:
    enabled: true

Structure with Subcharts

fullstack/
โ”œโ”€โ”€ Chart.yaml        # Has dependencies
โ”œโ”€โ”€ values.yaml       # Override subchart values
โ”œโ”€โ”€ templates/
โ”‚   โ””โ”€โ”€ app.yaml
โ””โ”€โ”€ charts/
    โ”œโ”€โ”€ postgresql-12.x.tgz
    โ””โ”€โ”€ redis-18.x.tgz

Commands

helm dep update ./fullstack   # Download/update deps
helm dep list ./fullstack     # List dependencies
helm install full ./fullstack # Deploy everything
helm get values full          # See current values

Chapter Summary

  • Understand core concepts and principles
  • Master implementation methods and techniques
  • Familiar with common issues and solutions
  • Able to apply in real projects

Further Reading

  • Official documentation and API references
  • Open source examples on GitHub
  • Technical books and online courses
  • Community discussions and tech blogs

Implementation Example

Basic Example

# This section provides a complete implementation example

Steps

  1. Setup: Configure development environment
  2. Data: Prepare required data
  3. Implementation: Build core functionality
  4. Testing: Verify correctness
  5. Optimization: Improve performance

Common Errors

| Error Type | Cause | Solution | |------------|-------|----------| | Compilation | Syntax | Check code syntax | | Runtime | Environment | Verify dependencies installed | | Logic | Algorithm | Step-by-step debugging | | Performance | Efficiency | Use profilers |

Code Example

import sys

def main():
    print("Hello, World!")

if __name__ == "__main__":
    main()

References

  • Official documentation
  • API reference
  • Open source examples
  • Community discussions

Dependency Conditions

Conditions control whether a dependency is installed based on a values field.

Condition Syntax

dependencies:
  - name: postgresql
    version: 12.x
    repository: https://charts.bitnami.com/bitnami
    condition: postgresql.enabled

This condition checks .Values.postgresql.enabled. If false, the subchart is skipped.

Values.yaml Control

# Parent chart values.yaml
postgresql:
  enabled: true        # Install PostgreSQL
  postgresqlDatabase: myapp
  postgresqlUsername: myapp
  postgresqlPassword: secret123

redis:
  enabled: false       # Skip Redis

Dependency Tags

Tags group multiple dependencies together for bulk enabling/disabling.

dependencies:
  - name: postgresql
    version: 12.x
    repository: https://charts.bitnami.com/bitnami
    tags:
      - database
  - name: mongodb
    version: 13.x
    repository: https://charts.bitnami.com/bitnami
    tags:
      - database
  - name: redis
    version: 17.x
    repository: https://charts.bitnami.com/bitnami
    tags:
      - cache

Control with Tags

# Enable all database dependencies
tags:
  database: true
  cache: false

Condition vs Tag Precedence

| Setting | Effect | |---------|--------| | condition: redis.enabled and .Values.redis.enabled: false | Subchart skipped | | tags: [cache] and .tags.cache: false | All cache-tagged subcharts skipped | | Both condition and tag | Condition takes precedence |

Parent-Child Value Passing

Values flow from parent to subcharts. Subcharts access parent values with the .global prefix.

Global Values

# Parent values.yaml
global:
  imageRegistry: my-registry.internal
  storageClass: fast-ssd

database:
  enabled: true
  size: 20Gi

Subchart accesses:

  • .Values.global.imageRegistry โ†’ my-registry.internal
  • .Values.size โ†’ 20Gi (subchart's own value takes precedence over parent)

Exporting Values from Subcharts

Subcharts can export values that the parent chart reads.

# Subchart values.yaml
exports:
  data:
    url: http://{{ .Release.Name }}-redis:6379
    port: 6379

# Parent chart accesses:
# {{ .Values.redis.exports.data.url }}

Dependency Update Commands

# Add dependencies after editing Chart.yaml
helm dependency update ./mychart

# List dependencies
helm dependency list ./mychart

# Build dependencies (download and lock)
helm dependency build ./mychart

# Delete dependency lock file
rm -f Chart.lock

Practical: Umbrella Chart

An umbrella chart combines multiple subcharts into one deployable unit.

Umbrella Chart Structure

umbrella-app/
  Chart.yaml
  values.yaml
  charts/          # Subcharts live here after update/build
  templates/
    _helpers.tpl
    ingress.yaml   # Shared ingress routing to subcharts
    configmap.yaml # Shared configuration

Umbrella Chart Example

# umbrella-app/Chart.yaml
apiVersion: v2
name: umbrella-app
description: Umbrella chart combining frontend, API, database
type: application
version: 1.0.0
dependencies:
  - name: frontend
    version: 0.2.0
    repository: http://my-chart-repo/
  - name: api
    version: 0.5.0
    repository: http://my-chart-repo/
  - name: postgresql
    version: 12.x
    repository: https://charts.bitnami.com/bitnami
    condition: postgresql.enabled

Summary

Chart dependencies enable composing complex applications from reusable subcharts. Use conditions and tags for fine-grained control over which subcharts deploy.

Key takeaways:

  • Dependencies are declared in Chart.yaml and stored in charts/ after update |
  • condition enables/disables a single subchart based on a values field |
  • tags group multiple subcharts for bulk enable/disable |
  • Global values propagate from parent to all subcharts |
  • Subcharts can export values for parent charts to consume |
  • helm dependency update downloads and locks dependency versions |
  • Umbrella charts combine subcharts into single deployable units |
  • Chart.lock locks dependency versions for reproducible builds |

What's Next: Hooks and Lifecycle

The next chapter covers Helm hooks and release lifecycle management.

Unlock Full Tutorial

This chapter is paid content. Join the project to unlock over 5000 words of deep analysis, including 10+ god-tier Prompts and real Source Code examples!