<p>I am learning to use k8s and I have a problem. I have been able to perform several deployments with the same yml without problems. My problem is that when I mount the secret volume it loads me the directory with the variables but it does not detect them as environments variable</p>
<p>my secret</p>
<pre><code>apiVersion: v1
kind: Secret
metadata:
  namespace: insertmendoza
  name: authentications-sercret
type: Opaque
data:
  DB_USERNAME: aW5zZXJ0bWVuZG96YQ==
  DB_PASSWORD: aktOUDlaZHRFTE1tNks1

  TOKEN_EXPIRES_IN: ODQ2MDA=
  SECRET_KEY: aXRzaXNzZWd1cmU=

apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: insertmendoza
  name: sarys-authentications
spec:
  replicas: 1
  selector:
    matchLabels:
      app: sarys-authentications
  template:
    metadata:
      labels:
        app: sarys-authentications
    spec:
      containers:
        - name: sarys-authentications
          image: 192.168.88.246:32000/custom:image
          imagePullPolicy: Always
          resources:
            limits:
              memory: &quot;500Mi&quot;
              cpu: &quot;50m&quot;
          ports:
            - containerPort: 8000

          envFrom:
            - configMapRef:
                name: authentications-config

          volumeMounts:
            - name: config-volumen
              mountPath: /etc/config/
              readOnly: true

            - name: secret-volumen
              mountPath: /etc/secret/
              readOnly: true

      volumes:
        - name: config-volumen
          configMap:
            name: authentications-config

        - name: secret-volumen
          secret:
            secretName: authentications-sercret

&gt; microservice@1.0.0 start
&gt; node dist/index.js
{
  ENGINE: 'postgres',
  NAME: 'insertmendoza',
  USER: undefined, &lt;-- not load 
  PASSWORD: undefined,&lt;-- not load 
  HOST: 'db-service',
  PORT: '5432'
}
</code></pre>
<p>if I add them manually if it recognizes them</p>
<pre><code> env:
            - name: DB_USERNAME
              valueFrom:
                secretKeyRef:
                  name: authentications-sercret
                  key: DB_USERNAME

            - name: DB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: authentications-sercret
                  key: DB_PASSWORD

&gt; microservice@1.0.0 start
&gt; node dist/index.js
{
  ENGINE: 'postgres',
  NAME: 'insertmendoza',
  USER: 'insertmendoza', &lt;-- work 
  PASSWORD: 'jKNP9ZdtELMm6K5', &lt;-- work
  HOST: 'db-service',
  PORT: '5432'
}
listening queue
listening on *:8000
</code></pre>
<p>in the directory where I mount the secrets exist!</p>
<pre><code>/etc/secret # ls
DB_PASSWORD       DB_USERNAME       SECRET_KEY        TOKEN_EXPIRES_IN
/etc/secret # cat DB_PASSWORD 
jKNP9ZdtELMm6K5/etc/secret # 
</code></pre>
<h5>EDIT</h5>
<p>My solution speed is</p>
<pre><code>envFrom:
        - configMapRef:
            name: authentications-config

        - secretRef: &lt;&lt;--
            name: authentications-sercret &lt;&lt;--
</code></pre>
<p>I hope it serves you, greetings from Argentina Insert Mendoza</p>

Nelson Javier Avila
<p>If I understand the problem correctly, you aren't getting the secrets loaded into the environment. It looks like you're loading it incorrectly, use the <code>envFrom</code> form as documented <a href="https://kubernetes.io/docs/concepts/configuration/secret/#use-case-as-container-environment-variables" rel="nofollow noreferrer">here</a>.</p>
<p>Using your example it would be:</p>
<pre><code>apiVersion: v1
kind: Secret
metadata:
  namespace: insertmendoza
  name: authentications-sercret
type: Opaque
data:
  DB_USERNAME: aW5zZXJ0bWVuZG96YQ==
  DB_PASSWORD: aktOUDlaZHRFTE1tNks1

  TOKEN_EXPIRES_IN: ODQ2MDA=
  SECRET_KEY: aXRzaXNzZWd1cmU=

---

apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: insertmendoza
  name: sarys-authentications
spec:
  replicas: 1
  selector:
    matchLabels:
      app: sarys-authentications
  template:
    metadata:
      labels:
        app: sarys-authentications
    spec:
      containers:
        - name: sarys-authentications
          image: 192.168.88.246:32000/custom:image
          imagePullPolicy: Always
          resources:
            limits:
              memory: &quot;500Mi&quot;
              cpu: &quot;50m&quot;
          ports:
            - containerPort: 8000

          envFrom:
            - configMapRef:
                name: authentications-config

            - secretRef:
                name: authentications-sercret

          volumeMounts:
            - name: config-volumen
              mountPath: /etc/config/
              readOnly: true
      volumes:
        - name: config-volumen
          configMap:
            name: authentications-config
</code></pre>
<p>Note the volume and mount was removed and just add the <code>secretRef</code> section. Those should now be exported as environment variables in your pod.</p>
