<p>I have a deployment for which the env variables for pod are set via config map.</p>

<pre><code>    envFrom:
    - configMapRef:
        name: map
</code></pre>

<p>My config map will look like this</p>

<pre><code>apiVersion: v1
data:
  HI: HELLO
  PASSWORD: PWD
  USERNAME: USER
kind: ConfigMap
metadata:
  name: map
</code></pre>

<p>all the pods have these env variables set from map. Now If I change the config map file and apply - <code>kubectl apply -f map.yaml</code> i get the confirmation that <code>map is configured</code>. However it does not trigger new pods creation with updated env variables.</p>

<p>Interestingly this one works</p>

<p><code>kubectl set env deploy/mydeploy PASSWORD=NEWPWD</code></p>

<p>But not this one</p>

<pre><code>kubectl set env deploy/mydeploy --from=cm/map
</code></pre>

<p>But I am looking for the way for new pods creation with updated env variables via config map!</p>

<blockquote>
  <p>Interestingly this one works</p>
  
  <p>kubectl set env deploy/mydeploy PASSWORD=NEWPWD</p>
  
  <p>But not this one</p>
  
  <p>kubectl set env deploy/mydeploy --from=cm/map</p>
</blockquote>

<p>This is expected behavior. Your pod manifest hasn't changed in second command (when you use the <code>cm</code>), that's why Kubernetes not recreating it.</p>

<p>There are several ways to deal with that. Basically what you can do is artificially change Pod manifest every time ConfigMap changes, e.g. adding annotation to the Pod with sha256sum of ConfigMap content. This is actually what Helm suggests you do. If you are using Helm it can be done as:</p>

<pre><code>kind: Deployment
spec:
  template:
    metadata:
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
[...]
</code></pre>

<p>From here: <a href="https://github.com/helm/helm/blob/master/docs/charts_tips_and_tricks.md#automatically-roll-deployments-when-configmaps-or-secrets-change" rel="nofollow noreferrer">https://github.com/helm/helm/blob/master/docs/charts_tips_and_tricks.md#automatically-roll-deployments-when-configmaps-or-secrets-change</a></p>

<p>Just make sure you add annotation to Pod (template) object, not the Deployment itself.</p>
