<p>I have a Helm chart containing two subcharts, <code>charts/subchart1</code> and <code>charts/subchart2</code>.  Each of the subcharts has its own <code>values.yaml</code>, <code>templates/deployment.yaml</code>, and similar files.</p>
<p>In the parent chart's <code>values.yaml</code> file I am using a parameter like:</p>
<pre class="lang-yaml prettyprint-override"><code>subchart1:
  serverPort: 1234
</code></pre>
<p>I can use this value from subchart1.</p>
<p>However, I want to use the same value in the <code>subchart2/templates/service.yaml</code> file.  Accessing using <code>{{ .Values.subchart1.serverPort }}</code> is not working.  Is there any way to access it?</p>

rebonta deb
<p>This is achievable, but it will be more complicated.</p>
<p>❗❗❗ You may need to learn a few concepts first.</p>
<ol>
<li><a href="https://helm.sh/docs/chart_template_guide/subcharts_and_globals/" rel="nofollow noreferrer">Subcharts and Global Values</a></li>
<li><a href="https://helm.sh/docs/helm/helm_dependency/" rel="nofollow noreferrer">Dependency</a></li>
<li><a href="https://helm.sh/docs/topics/charts/#importing-child-values-via-dependencies" rel="nofollow noreferrer">Exports and Imports values</a></li>
</ol>
<hr />
<p>Here is an example:</p>
<p>demo struct</p>
<pre><code>multi
├── Chart.yaml
├── charts
│   ├── sub0
│   │   ├── Chart.yaml
│   │   ├── charts
│   │   ├── templates
│   │   │   └── configmap.yaml
│   │   └── values.yaml
│   └── sub1
│       ├── Chart.yaml
│       ├── charts
│       ├── templates
│       │   └── configmap.yaml
│       └── values.yaml
├── templates
│   └── configmap.yaml
└── values.yaml
</code></pre>
<ul>
<li>multi: parent chart</li>
<li>sub0: sub-chart 0</li>
<li>sub1: cub-chart 1</li>
</ul>
<p>We will show how to use <code>test1: t1</code> in <code>sub1</code>, which defined in <code>sub0</code></p>
<p>multi/charts/sub0/templates/configmap.yaml</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-cm
data:
  sub0: {{ .Values.sub0 }}
  g0: {{ .Values.global.test0 }}
  g1: {{ .Values.global.test1 }}
</code></pre>
<p>multi/charts/sub0/values.yaml</p>
<pre class="lang-yaml prettyprint-override"><code>sub0: sub0

global:
  test0: t0

exports:
  data:
    global:
      test1: t1
</code></pre>
<p>multi/charts/sub1/templates/configmap.yaml</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-cm
data:
  sub1: {{ .Values.sub1 }}
  g1: {{ .Values.global.test1 }}
  g2: {{ .Values.global.test2 }}
</code></pre>
<p>multi/charts/sub1/values.yaml</p>
<pre class="lang-yaml prettyprint-override"><code>sub1: sub1
</code></pre>
<p>multi/templates.yaml</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-cm
data:
  dessert: {{ .Values.parent }}
  g1: {{ .Values.global.test1 }}
  g2: {{ .Values.global.test2 }}
</code></pre>
<p>multi/values.yaml</p>
<pre class="lang-yaml prettyprint-override"><code>parent: parent

global:
  test2: t2
</code></pre>
<p>❗ multi/Chart.yaml</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v2
name: multi
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
appVersion: &quot;1.16.0&quot;

dependencies:
  - name: sub0
    repository: file://./charts/sub0
    version: 0.1.0
    import-values:
      - data
</code></pre>
<hr />
<p><code>helm --dry-run --debug template multi .</code></p>
<pre class="lang-yaml prettyprint-override"><code>---
# Source: multi/charts/sub0/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: multi-cm
data:
  sub0: sub0
  g0: t0
  g1: t1
---
# Source: multi/charts/sub1/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: multi-cm
data:
  sub1: sub1
  g1: t1
  g2: t2
---
# Source: multi/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: multi-cm
data:
  dessert: parent
  g1: t1
  g2: t2
</code></pre>
<hr />
<p>As you can see, <code>sub1</code> reads <code>{{ .Values.global.test1 }}</code> from <code>parent-chart (multi)</code> by accessing global values.</p>
<p>But this value <code>{{ .Values.global.test1 }}</code> is not directly defined in <code>multi/values.yaml</code>, but is derived from <code>sub0</code>, and then ``multi<code>imports this value through</code>dependency```</p>
<p>Since the value of parent-chart in sub-chart needs to be accessed through the <code>global value</code>, the global value is written in the <code>values.yaml</code> of sub0</p>
<p>Of course, if you only need <code>sub1</code> to access the value in <code>sub0</code>, name can directly <code>dependency</code> the value in <code>sub0</code> in a similar way in <code>sub1</code>.</p>
<p>And our above approach will be accessible in all sub-charts.</p>
