<p>I posted a <a href="https://stackoverflow.com/questions/62354286/reference-to-environmental-variable-in-client-side-with-kubernetes-deployment">question</a> similar to this and tried to implement what the answer for this question said: <a href="https://stackoverflow.com/questions/59071793/how-to-access-kubernetes-container-environment-variables-from-next-js-applicatio">How to access Kubernetes container environment variables from Next.js application?</a></p>

<p>However, when I still call my environment variables doing <code>process.env.USERNAME</code>, I'm still getting undefined back... Am I doing something wrong in my deployment file? Here is a copy of my <code>deployment.yaml</code>:</p>

<pre><code>metadata:
  namespace: &lt;namespace&gt;
  releaseName: &lt;release name&gt;
  releaseVersion: 1.0.0
  target: &lt;target&gt;
auth:
replicaCount: 1
image:
  repository: '&lt;name of repository is here&gt;'
  pullPolicy: &lt;always&gt;
container:
  multiPorts:
  - containerPort: 443
  name: HTTPS
  protocol: TCP
  - containerPort: 80
  name: HTTP
  protocol: TCP
  env:
  - name: USERNAME
    valueFrom:
      secretKeyRef:
        name: my-username
        key: username
  - name: PASSWORD
    valueFrom:
      secretKeyRef:
        name: my-password
        key: password
  - name: HOST
    valueFrom:
      secretKeyRef:
        name: my-host
        key: host
  volumeMounts:
  - name: config
    mountPath: "/configMap"
    readOnly: true
volume:
  - name: config
    configMap:
      name: environmental-variables
resources:
  requests:
    cpu: 0.25
    memory: 256Mi
  limits:
    cpu: 1
    memory: 1024Mi
variables:
- name: NODE_ENV
  value: &lt;node env value here&gt;
ingress:
  enabled: true
  ingressType: &lt;ingressType&gt;
  applicationType: &lt;application type&gt;
  serviceEndpoint: &lt;endpoint&gt;
  multiPaths:
    - path: /
    - HTTPS
tls: 
  enabled: true
  secretName: &lt;name&gt;
autoscale:
  enabled: false
  minReplicas: 1
  maxReplicas: 5
  cpuAverageUtilization: 50
  memoryUtilizationValue: 50
annotations:
  ingress:
    nginx.ingress.kubernetes.io/affinity: &lt;affinity&gt;
    nginx.ingress.kubernetes.io/session-cookie-name: &lt;cookie-name&gt;
    nginx.ingress.kubernetes.io/session-cookie-expires: &lt;number&gt;
    nginx.ingress.kubernetes.io/session-cookie-max-age: &lt;number&gt;
</code></pre>

<p>I also created a <code>configMap.yaml</code> file, although I'm not sure if that's the right way to do this. Here is my <code>configMap.yaml</code> file:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: environmental-variables
data:
  .env: |
    USERNAME: &lt;username&gt;
    PASSWORD: &lt;password&gt;
    HOST: &lt;host&gt;
</code></pre>

<p>Any help will be greatly appreciated! Also I'm trying to make my environment variable as Secrets since I don't want to expose any of my variables because it contains sensitive information. I am trying to do this on a Node.js application using Express. Thank you!</p>

<p>EDIT: Here is how the Secrets part looks like in my yaml file</p>

<pre><code>secrets:
  - name: environmental-variables
  key: USERNAME
  - name: environmental-variables
  key: PASSWORD
</code></pre>

<p>How my Secrets yaml file looks like:</p>

<pre><code>kind: Secret
apiVersion: v1
metadata:
  name: environmental-variables
  namespace: tda-dev-duck-dev
data:
  USERNAME: &lt;username&gt;
  PASSWORD: &lt;password&gt;
</code></pre>

fairlyMinty
<p>After days of figuring out how to use Secrets as an environmental variable, I figured out how to reference it in my nodejs application!</p>

<p>Before I was doing the normal way of calling environmental variables, <code>process.env.VARIABLE_NAME</code>, but that did not work for me when I had Secrets as an environment variable. In order to get the value of the variable, I had to do <code>process.env.ENVIRONMENTAL_VARIABLES_USERNAME</code> in my Javascript file and that worked for me! Where <code>ENVIRONMENTAL_VARIABLES</code> is the <code>name</code> and <code>USERNAME</code> is the key!</p>

<p>Not sure if this will help anyone else but this is how I managed to access my Secrets in my nodejs application!</p>
