<p>Say I want the following secrets to be used in a db connection string inside a helm template:</p>

<pre><code>- name: DBUSER
  valueFrom:
   secretKeyRef:
     name: dbadmin
     key: username
- name: DBPASS
   valueFrom:
    secretKeyRef:
      name: dbadmin
      key: password
</code></pre>

<p>Later I want to create this:</p>

<pre><code>- name: Database__ConnectionString
  value: "server=something.com;port=3306;user=$DBUSER;password=$DBPASS;database=dbname"
</code></pre>

<p>How do I access the env values of DBUSER and DBNAME inside of that connection string value?</p>

<p>Many places in a pod spec support <code>$(VARIABLE_NAME)</code> syntax.  In particular, the <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.17/#envvar-v1-core" rel="nofollow noreferrer">API documentation for an <code>EnvVar</code> object</a> specifies</p>

<blockquote>
  <p><code>value</code> (<em>string</em>): Variable references $(VAR_NAME) are expanded using the previous defined environment variables in the container and any service environment variables.</p>
</blockquote>

<p>so you should be able to say something like</p>

<pre><code>- name: Database__ConnectionString
  value: "server=something.com;port=3306;user=$(DBUSER);password=$(DBPASS);database=dbname"
</code></pre>

<p>(Note the parentheses around <code>$(DBUSER)</code> and <code>$(DBPASS)</code>.)</p>

<p>(In this specific case some database libraries will let you specify all of the individual parts of a connection string as separate environment variables, so instead of doing this you might be able to set environment variables <a href="https://www.postgresql.org/docs/12/libpq-envars.html" rel="nofollow noreferrer"><code>PGUSER</code> and <code>PGPASSWORD</code></a> if you're using PostgreSQL for example.)</p>
