<p>The pod that created in the same <code>default</code> namespace as it's secret does not see values from it.</p>

<p>Secret's file contains following:</p>

<pre><code>apiVersion: v1
kind: Secret
metadata:
  name: backend-secret
data:
  SECRET_KEY: &lt;base64 of value&gt;
  DEBUG: &lt;base64 of value&gt;
</code></pre>

<p>After creating this secret via <code>kubectl create -f backend-secret.yaml</code> I'm launching pod with the following configuration:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: backend
spec:
  containers:
    - image: backend
      name: backend
      ports:
        - containerPort: 8000
  imagePullSecrets:
    - name: dockerhub-credentials
  volumes:
  - name: secret
    secret:
      secretName: backend-secret
</code></pre>

<p>But pod crashes after trying to extract this environment variable via python's <code>os.environ['DEBUG']</code> line.</p>

<p>How to make it work?</p>

Vassily
<p>If you mount secret as volume, it will be mounted in a defined directory where key name will be the file name. For example click <a href="https://kubernetes.io/docs/concepts/configuration/secret/#secret-files-permissions" rel="nofollow noreferrer">here</a></p>

<p>If you want to access secrets from the environment into your pod then you need to use secret in an environment variable like following. </p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: backend
spec:
  containers:
    - image: backend
      name: backend
      ports:
        - containerPort: 8000
      env:
      - name: DEBUG
        valueFrom:
          secretKeyRef:
            name: backend-secret
            key: DEBUG
      - name: SECRET_KEY
        valueFrom:
          secretKeyRef:
            name: backend-secret
            key: SECRET_KEY
  imagePullSecrets:
    - name: dockerhub-credentials
</code></pre>

<p>Ref: <a href="https://kubernetes.io/docs/concepts/configuration/secret/#using-secrets-as-environment-variables" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/configuration/secret/#using-secrets-as-environment-variables</a></p>
