<p>I have an existing kubernetes deployment which is running fine. Now I want to edit it with some new environment variables which I will use in the pod. 
Editing a deployment will delete and create new pod or it will update the existing pod.
My requirement is I want to create a new pod whenever I edit/update the deployment.</p>

Farooq Rahman
<p>Kubernetes is always going to recreate your pods in case you change/create env vars. </p>

<p>Lets check this together creating a deployment without any env var on it:</p>

<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
</code></pre>

<p>Let's check and note these pod names so we can compare later: </p>

<pre><code>$ kubectl get pod 
NAME                                READY   STATUS    RESTARTS   AGE
nginx-deployment-56db997f77-9mpjx   1/1     Running   0          8s
nginx-deployment-56db997f77-mgdv9   1/1     Running   0          8s
nginx-deployment-56db997f77-zg96f   1/1     Running   0          8s
</code></pre>

<p>Now let's edit this deployment and include one env var making the manifest look like this: </p>

<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        env:
          - name: STACK_GREETING
            value: "Hello from the MARS"
        ports:
        - containerPort: 80
</code></pre>

<p>After we finish the edition, let's check our pod names and see if it changed: </p>

<pre><code>$ kubectl get pod 
nginx-deployment-5b4b68cb55-9ll7p   1/1     Running   0          25s
nginx-deployment-5b4b68cb55-ds9kb   1/1     Running   0          23s
nginx-deployment-5b4b68cb55-wlqgz   1/1     Running   0          21s
</code></pre>

<p>As we can see, all pod names changed. Let's check if our env var got applied: </p>

<pre><code>$ kubectl exec -ti nginx-deployment-5b4b68cb55-9ll7p -- sh -c  'echo $STACK_GREETING'
Hello from the MARS
</code></pre>

<p>The same behavior will occur if you change the var or even remove it. All pods need to be removed and created again for the changes to take place. </p>
