<p>I'd like to know whether I'm able to propagate environment variables from a file.</p>

<p>Guess I have a file like this:</p>

<pre><code>ENV_VARIABLE_USERNAME=username
ENV_VARIABLE_PASSWORD=password
</code></pre>

<p>I'd like when I pod kicks off, this content file is propagated as environment variables.</p>

<p>Is it possible?</p>

Jordi
<p>Generally speaking, for environment variables, you would do it through a configMap. But as this is a username and password (sensitive information), you can do it through a secret.</p>

<p>For example, given the Pod (redis, for this example) and the Secret below:</p>

<pre><code>apiVersion: v1
kind: Secret
metadata:
  name: credentials
type: Opaque
data:
  username: dXNlcm5hbWU=        //username -&gt; encoded base64
  password: cGFzc3dvcmQ=        //password -&gt; encoded base64
</code></pre>

<p>Note: you need to have all data in a secret encoded. This one is encoded with base64:</p>

<pre><code>echo -n username | base64
</code></pre>

<p>And the pod:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: redis-pod
spec:
  containers:
  - name: redis
    image: redis
    env:
      - name: SECRET_USERNAME
        valueFrom:
          secretKeyRef:
            name: credentials
            key: username
      - name: SECRET_PASSWORD
        valueFrom:
          secretKeyRef:
            name: credentials
            key: password
  restartPolicy: Never
</code></pre>

<p>Now if you would run <code>env | grep SECRET</code> in the pod, I would get the variable correctly initialized:</p>

<pre><code>nerus:~/workspace (master) $ kubectl exec redis-pod env | grep SECRET
SECRET_USERNAME=username
SECRET_PASSWORD=password
</code></pre>
