<p>I run this Job:</p>
<pre><code>kubectl apply -f - &lt;&lt;EOF
apiVersion: batch/v1
kind: Job
metadata:
  name: sample
spec:
  template:
    spec:
      containers:
      - command:
        - /bin/bash
        - -c
        - |
          env
          echo &quot;MY_VAR : ${MY_VAR}&quot;
          sleep 800000
        env:
        - name: MY_VAR
          value: MY_VALUE
        image: mcr.microsoft.com/azure-cli:2.0.80
        imagePullPolicy: IfNotPresent
        name: sample
      restartPolicy: Never
  backoffLimit: 4
EOF
</code></pre>
<p>But when I look at the log the value <code>MY_VALUE</code> its empty even though <code>env</code> prints it:</p>
<pre><code>$ kubectl logs -f sample-7p6bp
...
MY_VAR=MY_VALUE
...
MY_VAR : 
</code></pre>
<p>Why does this line contain an empty value for <code>${MY_VAR}</code>:</p>
<pre><code>echo &quot;MY_VAR : ${MY_VAR}&quot;
</code></pre>
<p>?</p>
<p><strong>UPDATE:</strong> Tried the same with a simple pod:</p>
<pre><code>kubectl -f - &lt;&lt;EOF
apiVersion: v1
kind: Pod
metadata:
  name: sample
spec:
  containers:
  - name: sample
    imagePullPolicy: Always
    command: [&quot;/bin/sh&quot;, &quot;-c&quot;, &quot;echo BEGIN ${MY_VAR} END&quot;]
    image: radial/busyboxplus:curl
    env:
    - name: MY_VAR
      value: MY_VALUE
EOF
</code></pre>
<p>Same/empty result:</p>
<pre><code>$ kubectl logs -f sample
BEGIN END
</code></pre>

<p>The reason this happens is because your shell expands the variable <code>${MY_VAR}</code> before it's ever sent to the kubernetes. You can disable parameter expansion inside of a heredoc by quoting the terminator:</p>
<pre><code>kubectl apply -f - &lt;&lt;'EOF'
</code></pre>
<p>Adding these quotes should resolve your issue.</p>
