Skip to content

Instantly share code, notes, and snippets.

@initcron
Last active May 13, 2024 03:56
Show Gist options
  • Save initcron/25be28ab712adaab380b37e2f4e11eab to your computer and use it in GitHub Desktop.
Save initcron/25be28ab712adaab380b37e2f4e11eab to your computer and use it in GitHub Desktop.

Scenario

Imagine we have a parent chart and a child chart. Each has a configuration value named replicaCount, which specifies the number of replicas for a deployment. We want to be able to override this value for different environments using separate files.

Directory Structure

parent/
  - charts/
    - child/
      - templates/
      - Chart.yaml
      - values.yaml
  - templates/
  - Chart.yaml
  - values.yaml

environment/
  - values-dev.yaml
  - values-prod.yaml

Chart Configurations

File : child/Chart.yaml

apiVersion: v2
name: child
description: A Helm chart for the Child component
version: 0.1.0

File : Child/values.yaml

replicaCount: 1

File : parent/Chart.yaml

apiVersion: v2
name: parent
description: A Helm chart for Kubernetes that includes the Child component
version: 0.1.0
dependencies:
  - name: child
    version: 0.1.0
    repository: "file://./charts/child"

File : parent/values.yaml

replicaCount: 2
child:
  replicaCount: 2  # This overrides the child's default replica count


Environment Specific Overrides

File : environment/values-dev.yaml

replicaCount: 3
child:
  replicaCount: 3  # Development environment requires more replicas

File : environment/values-prod.yaml

replicaCount: 5
child:
  replicaCount: 5  # Production typically runs more replicas for high availability

Helm Command to Deploy

With these configurations, you can deploy the Helm chart for each environment using the respective values file to override the default and parent-defined settings:

# Deploy to development environment
helm upgrade --install my-parent-chart ./parent -f environment/values-dev.yaml

# Deploy to production environment
helm upgrade --install my-parent-chart ./parent -f environment/values-prod.yaml

Explanation

  • Default Values: Both the parent and child charts define a default replicaCount.
  • Parent Overriding Child: In the parent's values.yaml, we explicitly set child.replicaCount. This overrides the value defined in the child’s values.yaml.
  • Environment Overrides: The values-dev.yaml and values-prod.yaml files in the environment directory further override the replicaCount for both the parent and the child charts, specifically tailored to the needs of each environment.

This setup exemplifies a typical use case where values are cascaded and overridden in a Helm chart hierarchy, demonstrating flexibility and control over deployments in different environments.

File : ``

File : ``

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment