<p>I have a node.js application which is accessing environment variables like so:</p>
<pre><code>const pool = mysql.createPool({
  host: process.env.MYSQL_HOST,
  user: process.env.MYSQL_USER,
  port: process.env.MYSQL_PORT,
  password: process.env.MYSQL_PASSWORD,
  database: process.env.MYSQL_DB
});
</code></pre>
<p>The deployment is done via Kubernetes. Some of the environment variables, such as MYSQL_HOST, MYSQL_DB are set in plain form, the MYSQL_PASSWORD, however, is set via a secret. And the problem is that the regular environment variables are read by my node.js application just fine while the MYSQL_PASSWORD is not. But the problem is that when I try to see the value of MYSQL_PASSWORD in the list of the environment variables in the container - it shows the correct value.</p>
<p>Here's how the environment variable in question is set in the deployment yaml:</p>
<pre><code>- name: MYSQL_PASSWORD
  valueFrom:
      secretKeyRef:
         key: MYSQL_PASSWORD
         name: config-secret
</code></pre>
<p>And again - the value is visible when I run the <code>env</code> command in the container, but for some reason the node.js application doesn't pick it up.</p>
<p>Does anybody have any clue why my app would read the regular environment variables without issues but fails to read the ones set as secrets?</p>
<p>Thanks.</p>

cycero
<p>The <code>key</code> should be the once you used in your secret. For example, if you have:</p>
<pre class="lang-sh prettyprint-override"><code>kubectl create secret generic config-secret --from-literal=username=user --from-literal=password=pw
</code></pre>
<p>You should use it as follows:</p>
<pre class="lang-yaml prettyprint-override"><code>- name: MYSQL_PASSWORD
  valueFrom:
    secretKeyRef:
      name: config-secret
      key: password
</code></pre>
<p>Note that the <code>key</code> is not the same as the env variable name. It should be the one used to set the secret's key.</p>
