<p>for debug reasons I try to run a container (alpine) via <code>kubectl run</code> and set some Environment vars from ConfigMap or Secret. To do that I understood to use <code>--override=</code> parameter. But if I execute the Container and echo the vars nothing is set. Is my structure of my inline json wrong?</p>

<pre><code>kubectl run --dry-run=client --restart=Never --image=alpine -n app-ns psql-demo --overrides='
{
    "apiVersion": "v1",
    "spec": {        
        "env": [
            {
                "name": "POSTGRES_HOST",
                "valueFrom": {
                    "configMapKeyRef": {
                        "key": "POSTGRES_HOST",
                        "name": "db-config"
                    }
                }
            }
        ]
    }
}' -o yaml -- sh

</code></pre>

<p>I try to check it via <code>echo ${POSTGRES_HOST}</code>.</p>

<p>The ConfigMap config here:</p>

<pre><code>apiVersion: v1
data:
  POSTGRES_HOST: db.host.com
kind: ConfigMap
metadata:
  labels:
    component: postgres
  name: db-config
  namespace: app-ns
</code></pre>

<p>Any idea? Thanks a lot!</p>

Gerrit
<p>The struct of your json is a bit off, it should be something like this:</p>

<pre><code>{
  "spec": {
    "containers": {
      "env": [
        {
          "name": "POSTGRES_HOST",
          "valueFrom": {
            "configMapKeyRef": {
              "name": "db-config",
              "key": "POSTGRES_HOST"
            }
          }
        }
      ]
    }
  }
}
</code></pre>

<p>And note that the first "name" is the actual env variable name that will appear inside your container, it doesn't have to be identical to the actual key you used inside your configmap.</p>

<ul>
<li>It's important to note that <code>kubectl run</code> ignores unknown fields.</li>
</ul>

<p>To debug this, you can run the command you specified, and then in another terminal:</p>

<p><code>kubectl get pod POD_NAME -o json</code></p>

<p>From there you can see if the actual env specification structure differs from your json override value.</p>
