<p>I need to read a Kubernetes key and value from NodeJs. But am getting an undefined error.</p>
<p>Please find the below code.</p>
<p><strong>deployment.yaml</strong></p>
<pre><code>containers:
-   name: server
    env:
    -name: CLIENT_DEV
        valueFrom:
            secretKeyRef:
                name: dev1-creds-config
                key: clientId
</code></pre>
<p>The secretKeyRef value will be available in another yaml file. This will get read properly when the dev/local minikube build is running based on the region we are running.</p>
<p><strong>secrets.enc.yaml</strong></p>
<pre><code>apiVersion: v1
kind: Secret
metadata:
    name: dev1-creds-config
type: Opaque
data:
    clientId: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    username: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    password: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
</code></pre>
<p>The above one contains the encrypted values. This is created to ensure security.</p>
<p>The <strong>index.js</strong> file of NodeJs to read the value</p>
<pre><code>require(&quot;dotenv&quot;).config();
const express = require(&quot;express&quot;);
const app = express();

console.log(&quot;value..&quot;+processs.env.CLIENT_DEV);
const host = customHost || &quot;localhost&quot;;

app.listen(port,host,err =&gt; {
    if(err){
        return logger.error(err.message);
    }
    logger.appStarted(&quot;3000&quot;, host);
});
</code></pre>
<p><code>console.log(&quot;value..&quot;+processs.env.CLIENT_DEV);</code> this line is giving me &quot;undefined&quot;</p>
<p>My query is,</p>
<ol>
<li>is it possible to the yaml encrypted value from deployment yaml using Node js</li>
<li>is it possible to configure yaml key, value in .env file of Node Js</li>
</ol>
<p>Am not able to read this secret value from yaml file in my node js.</p>
<p>Please help me to resolve this issue.</p>
<p>Thanks in advance.</p>

Neela
<p>Check the indentation in your deployment.yaml, it should be like this:</p>
<pre class="lang-yaml prettyprint-override"><code>containers:
- name: server
  env:
    - name: CLIENT_DEV
      valueFrom:
        secretKeyRef:
          name: dev1-creds-config
          key: clientId
</code></pre>
<p>In your question the indentation is incorrect. But as long as your nodejs pods are running well, I think you just pasted it not very accurately.</p>
<p>Second, there is a typo <code>processs</code> in your JavaScript code. Correct the line:</p>
<pre><code>console.log(&quot;value..&quot;+process.env.CLIENT_DEV);
</code></pre>
<p>After verifying all of these, your NodeJs application will read the Kubernetes secret value.</p>
