<p>I have a nodejs application which stores variables in environment variables.</p>
<p>I'm using the <a href="https://www.npmjs.com/package/dotenv" rel="noreferrer">dotenv</a> module, so I have a <code>.env</code> file that looks like :</p>
<pre><code>VAR1=value1
VAR2=something_else
</code></pre>
<p>I'm currently setting up a BitBucket Pipeline to auto deploy this to a Kubernetes cluster.<br />
I'm not very familiar with kubernetes secrets, though I'm <a href="https://kubernetes.io/docs/concepts/configuration/secret/" rel="noreferrer">reading up on them</a>.</p>
<p>I'm wondering :</p>
<p><strong>Is there an easy way to send to a Docker-container / kubernetes-deployment all of the environment variables I have defined in my <code>.env</code> file so they are available in the pods my app is running in ?</strong></p>
<p>I'm hoping for an example <code>secrets.yml</code> file or similar which takes everything from <code>.env</code> and makes in into environment variables in the container.  But it could also be done in the BitBucket pipeline level, or at the Docker container level .. I'm not sure ...</p>

kris
<p><strong>Step 1:</strong> Create a k8s secret with your <code>.env</code> file:</p>
<pre class="lang-sh prettyprint-override"><code># kubectl create secret generic &lt;secret-name&gt; --from-env-file=&lt;path-to-env-file&gt; 

$ kubectl create secret generic my-env-list --from-env-file=.env 
secret/my-env-list created
</code></pre>
<p><strong>Step 2:</strong> Varify secret:</p>
<pre class="lang-sh prettyprint-override"><code>$ kubectl get secret my-env-list -o yaml
apiVersion: v1
data:
  VAR1: dmFsdWUx
  VAR2: c29tZXRoaW5nX2Vsc2U=
kind: Secret
metadata:
  name: my-env-list
  namespace: default
type: Opaque
</code></pre>
<p><strong>Step 3:</strong> Add <code>env</code> to your pod's container:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Pod
metadata:
  name: demo-pod
spec:
  containers:
    - name: demo-container
      image: k8s.gcr.io/busybox
      command: [ &quot;/bin/sh&quot;, &quot;-c&quot;, &quot;env&quot; ]
      envFrom:
      - secretRef:
          name: my-env-list # &lt;---- here
  restartPolicy: Never
</code></pre>
<p><strong>Step 4:</strong> Run the pod and check if the <code>env</code> exist or not:</p>
<pre class="lang-sh prettyprint-override"><code>$ kubectl apply -f pod.yaml 
pod/demo-pod created

$ kubectl logs -f demo-pod 
KUBERNETES_PORT=tcp://10.96.0.1:443
KUBERNETES_SERVICE_PORT=443
HOSTNAME=demo-pod
SHLVL=1
HOME=/root
KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1
VAR1=value1  # &lt;------------------------------------------------------here 
VAR2=something_else # &lt;-----------------------------------------------here
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
KUBERNETES_PORT_443_TCP_PORT=443
KUBERNETES_PORT_443_TCP_PROTO=tcp
KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443
KUBERNETES_SERVICE_PORT_HTTPS=443
PWD=/
KUBERNETES_SERVICE_HOST=10.96.0.1

</code></pre>
