Access parent (chart) context from subcharts

12/2/2019

I have a Helm Chart comprising of a few subcharts, sth like this:

├── Chart.yaml
├── README.md
├── charts
│   ├── nginx-1.0.0.tgz
│   └── redis-1.0.0.tgz
├── index.yaml
├── requirements.lock
├── requirements.yaml
├── subcharts
│   ├── nginx
│   │   ├── Chart.yaml
│   │   ├── templates
│   │   │   ├── deployment.yaml
│   │   │   ├── service.yaml
│   └── redis
│       ├── Chart.yaml
│       ├── templates
│       │   ├── deployment.yaml
│       │   └── service.yaml
│       └── values.yaml
└── values.yaml

In my root level values.yaml, I define the (per chart) values, under the corresponding yaml node, i.e. the file would look something like this:

redis:
  namespace: default
  replicas: 1
  image: redis
  tag: 5.0-alpine
  port: 6379
  imagePullPolicy: IfNotPresent
  serviceType: ClusterIP
  resources:
    requests:
      cpu: 200m
      memory: 512Mi
    limits:
      cpu: 1000M
      memory: 1500Mi
nginx:
  namespace: default
  istio:
    enabled: false
  replicas: 1
  image: redash/nginx
  tag: latest
  port: 80
  imagePullPolicy: IfNotPresent
  serviceType: LoadBalancer

And these values (the ones in the hierarchy <subchartname>.value are accessed as follows in a subchart template:

spec:
  replicas: {{ default 1 .Values.replicas }}

i.e. there is no reference to the subchart name, given that this becomes the root context for the template.

Is there a way so that my helm templates access the parent (root) context values?

I want to do this so I can share values across subcharts in a DRY mode.

i.e. more or less my question becomes:

how should I access from my subchart templates, values in the root level?

myvariable1:
    value1
myvarianle2:
    value2
-- pkaramol
kubernetes
kubernetes-helm

1 Answer

12/3/2019

I think you need to use global chart values which can be shared across subcharts . Link to doc https://helm.sh/docs/topics/chart_template_guide/subcharts_and_globals/#global-chart-values

-- shubham_asati
Source: StackOverflow