<p>I'm trying to get secrets in init container and pass them to the main container. I have 2 questions here,</p>
<ol>
<li>How to pass external secrets in init container</li>
<li>How to call them as env variables in main container</li>
</ol>

Manasa
<p>you can mount the same secret as Environment variables on both initContainer and mainContainer.</p>
<p>Given a secret such as:</p>
<pre><code>k create secret generic mysecret --from-literal=key=secret
</code></pre>
<p>That will be something like:</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: mypod
  name: mypod
spec:
  initContainers:
  - name: init
    image: busybox
    env:
    - name: SECRET
      valueFrom:
        secretKeyRef:
          name: mysecret
          key: key
    command: ['sh','-c','echo $SECRET']
  containers:
  - image: busybox
    name: mypod
    resources: {}
    env:
    - name: SECRET
      valueFrom:
        secretKeyRef:
          name: mysecret
          key: key
    command: ['sh','-c','echo $SECRET']
  dnsPolicy: ClusterFirst
  restartPolicy: Never
status: {}
</code></pre>
<p>When running the pods, see them both printing the content of the same secret.</p>
<pre><code>kubectl logs mypod -c init
secret

kubectl logs mypod
secret
</code></pre>
