<p>How to read environment variables in kubernetes yaml file?
for example, I want to change the docker image tag but do not want to rewrite the file, like this</p>

<pre><code>apiVersion: v1
kind: ReplicationController
...
spec:
  containers:
    - name: myapp
      image: myapp:${VERSION}
 ...
</code></pre>

<p>With this I can do <code>kubectl rolling-update</code> without updating the yaml file.</p>

<p>thanks</p>

<p>If you want a simple, lightweight approch you might try using <a href="https://www.gnu.org/software/gettext/manual/html_node/envsubst-Invocation.html" rel="nofollow noreferrer">envsubst</a>. So assuming your example is in a file called <code>example.yaml</code> in a bash shell you'd execute:</p>
<pre><code>export VERSION=69
envsubst &lt; example.yaml | kubectl apply -f -
</code></pre>
<p>Also recent versions of <a href="https://github.com/kubernetes-sigs/kustomize/blob/master/examples/image.md" rel="nofollow noreferrer">Kustomize</a> can do it too.</p>
