<p>I am trying to set some environment variables in docker container, Below is the env definition part from the kubernetes pod definition.</p>

<pre><code>              env:
                - name: NRIA_LICENSE_KEY
                  value: NRIA_LICENSE_KEY
                -name:  NRIA_DISPLAY_NAME
                  value: abc-$HOSTNAME
</code></pre>

<p>When I echo the value of NRIA_DISPLAY_NAME variable in the container, however, I am getting below output, which is not expected.</p>

<pre><code>echo $NRIA_DISPLAY_NAME
NRIA_DISPLAY_NAME=abc-\$HOSTNAME
</code></pre>

<p><strong>expected output:</strong></p>

<pre><code>    echo $NRIA_DISPLAY_NAME
    NRIA_DISPLAY_NAME=abc-myhostname ($HOSTNAME should be replaced with the actual hostname value)
</code></pre>

<p>I tried setting it in command tag as well, that didn't work.</p>

<pre><code> command: [ "bash", "-c", "export NRIA_DISPLAY_NAME=abc-$HOSTNAME" ]
</code></pre>

<pre><code>- name:  NRIA_DISPLAY_NAME
  value: abc-$HOSTNAME
</code></pre>

<p>should have two changes made to it:</p>

<ol>
<li><p>Ensure the thing you wish to have substituted is <em>also</em> present in the <code>env:</code> block -- I know you might think <code>$HOSTNAME</code> is universally populated, but that's not always true, and it is for sure not true in the kubernetes mental model</p></li>
<li><p>Use the syntax <code>$(INTERPOLATION_HERE)</code> rather than the bash-centric <code>$VAR</code> or <code>${VAR}</code>. That syntax is documented in the <code>PodSpec</code> reference</p></li>
</ol>

<p>Thus:</p>

<pre><code>env:
- name: HOSTNAME
  valueFrom:
    fieldRef:
      fieldPath: metadata.name
      # or "status.hostIP" or "spec.nodeName" etc
- name: NRIA_DISPLAY_NAME
  value: abc-$(HOSTNAME)
</code></pre>
