<p>I have the following situation:</p>

<p>I have multiple deployments running the same image and are configured identically except for the environmental variables.</p>

<p>Now my question is, is there an easy way to update for example the image of all these deployments instead of doing it one by one?</p>

<p>I haven't found a solution, but I think this should be possible with the use of labels?</p>

<p>Or is there a better way to deploy the same deployments with only different environmental variables?</p>

Ron Nabuurs
<p>Yes, you can, this is what labels are for. They are good for grouping similar objects.
Here is the minimal reproducible example.<br>
Create 2 deployments with the same label <code>app=nginx</code>:</p>

<pre><code>$ kubectl run --image=nginx --overrides='{ "metadata": {"labels": {"app": "nginx"}}, "spec":{"template":{"spec": {"containers":[{"name":"nginx-container", "image": "nginx"}]}}}}' nginx-1
deployment.apps/nginx-1 created
$ kubectl run --image=nginx --overrides='{ "metadata": {"labels": {"app": "nginx"}}, "spec":{"template":{"spec": {"containers":[{"name":"nginx-container", "image": "nginx"}]}}}}' nginx-2
deployment.apps/nginx-2 created
</code></pre>

<p>Here are our deployments:</p>

<pre><code>$ kubectl get deploy -o wide --show-labels 
NAME      READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS        IMAGES   SELECTOR      LABELS
nginx-1   1/1     1            1           20s   nginx-container   nginx    run=nginx-1   app=nginx,run=nginx-1
nginx-2   1/1     1            1           16s   nginx-container   nginx    run=nginx-2   app=nginx,run=nginx-2
</code></pre>

<p>Then we can use <code>set</code> command and filter desired deployments using label <code>app=nginx</code>:</p>

<pre><code>$ kubectl set image deployment -l app=nginx nginx-container=nginx:alpine
deployment.extensions/nginx-1 image updated
deployment.extensions/nginx-2 image updated
</code></pre>

<p>And see the results:</p>

<pre><code>$ kubectl get deploy -o wide --show-labels
NAME      READY   UP-TO-DATE   AVAILABLE   AGE     CONTAINERS        IMAGES         SELECTOR      LABELS
nginx-1   1/1     1            1           6m49s   nginx-container   nginx:alpine   run=nginx-1   app=nginx,run=nginx-1
nginx-2   1/1     1            1           6m45s   nginx-container   nginx:alpine   run=nginx-2   app=nginx,run=nginx-2
</code></pre>
