<p>I am trying to pass an environment variable in my deployment that should define a prefix based on a version number:</p>
<pre><code>env:
  - name: INDEX_PREFIX
    value: myapp-$(VERSION)
</code></pre>
<p><code>$(VERSION)</code> is not defined in my deployment but is set in the docker image used by the pod.
I tried to use both <code>$()</code> and <code>${}</code> but <code>VERSION</code> is not interpolated in the environment of my pod. In my pod shell doing <code>export TEST=myapp-${VERSION}</code> does work though.</p>
<p>Is there any way to achieve what I am looking for? ie setting an environment variable in my deployment that reference an environment variable set in the docker image?</p>

ITChap
<p><code>VERSION</code> is an environment variable of the docker image. So you can assign it a value either inside the container or by passing</p>
<pre><code>env: 
   - name : VERSION
     value : YOUR-VALUE
</code></pre>
<p>In your case, <code>VERSION</code> is either set by a script inside the docker container or in the Dockerfile.</p>
<p>You can do :</p>
<ol>
<li>In the Dockerfile, adding <code>ENV INDEX_PREFIX myapp-${VERSION}</code></li>
<li>Adding a script to your entrypoint as
<code>export  INDEX_PREFIX=myapp-${VERSION} </code></li>
</ol>
<p>In case you can't modify Dockerfile, you can try to :</p>
<ul>
<li>Get the image entrypoint file from the docker image (ie: /IMAGE-entrypoint.sh) and the image args(ie: IMAGE-ARGS). you can use <code>docker inspect IMAGE</code>.</li>
<li>Override the container command and args in the pod spec using a script.</li>
</ul>
<pre><code>   command:
           - '/bin/sh'
   args:
           - '-c'
           - |
             set -e
             set -x
             export INDEX_PREFIX=myapp-${VERSION} 
             IMAGE-entrypoint.sh IMAGE-ARGS
</code></pre>
<p>k8s documentation : <a href="https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/</a>
Hope it could help you.</p>
