<p>The <code>env</code> element added in <code>spec.containers</code> of a pod using K8 dashboard's <em>Edit</em> doesn't get saved. Does anyone know what the problem is? </p>

<p>Is there any other way to add environment variables to pods/containers? </p>

<p>I get this error when doing the same by editing the file using nano:</p>

<pre><code># pods "EXAMPLE" was not valid:
# * spec: Forbidden: pod updates may not change fields other than `containers[*].image` or `spec.activeDeadlineSeconds`
</code></pre>

<p>Thanks.</p>

<p>Not all fields can be updated. This fact is sometimes mentioned in the <code>kubectl explain</code> output for the object (and the error you got lists the fields that can be changed, so the others probably cannot).:</p>

<pre><code>$ kubectl explain pod.spec.containers.env
RESOURCE: env &lt;[]Object&gt;

DESCRIPTION:
     List of environment variables to set in the container. Cannot be updated.

    EnvVar represents an environment variable present in a Container.
</code></pre>

<p>If you deploy your Pods using a <a href="http://kubernetes.io/docs/user-guide/deployments/" rel="noreferrer">Deployment object</a>, then you can change the environment variables in <em>that</em> object with <code>kubectl edit</code> since the Deployment will roll out updated versions of the Pod(s) that have the variable changes and kill the older Pods that do not. Obviously, that method is not changing the Pod in place, but it is one way to get what you need.</p>

<p>Another option for you may be to use <a href="http://kubernetes.io/docs/user-guide/configmap/" rel="noreferrer">ConfigMaps</a>. If you use the volume plugin method for mounting the ConfigMap <em>and</em> your application is written to be aware of changes to the volume and reload itself with new settings on change, it may be an option (or at least give you other ideas that may work for you). </p>
