<p>For example, a deployment yaml file:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: guestbook
spec:
  replicas: 2
  template:
    metadata:
      labels:
        app: guestbook
      spec:
        container:
          - name: guestbook
            image: {{Here want to read value from config file outside}}
</code></pre>

<p>There is a <code>ConfigMap</code> feature with Kubernetes, but that's also write the key/value to the yaml file. Is there a way to set the key to environment variables?</p>

<p>You can also use <a href="https://www.gnu.org/software/gettext/manual/html_node/envsubst-Invocation.html" rel="noreferrer"><code>envsubst</code></a> when deploying.</p>
<p>e.g.</p>
<pre><code>cat app/deployment.yaml | envsubst | kubectl apply ...
</code></pre>
<p>It will replace all variables in the file with their values.
We are successfully using this approach on our CI when deploying to multiple environments, also to inject the <code>CI_TAG</code> etc into the deployments.</p>
