<p>I am new to Kubernetes. I have a K8 cluster with multiple deployments (more than 150), each having more than 4 pods scaled.
I have a requirement to increase resource limits for all deployments in the cluster; and I'm aware I can increase this directly via my deployment YAML.
However, I'm thinking if there is any way I can increase the resources for all deployments at one go.</p>
<p>Thanks for your help in advance.</p>

Aniruddha Salve
<p>There are few things to point out here:</p>
<ol>
<li>There is a <a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#patch" rel="noreferrer">kubectl patch</a> command that allows you to:</li>
</ol>
<blockquote>
<p>Update field(s) of a resource using strategic merge patch, a JSON
merge patch, or a JSON patch.</p>
<p>JSON and YAML formats are accepted.</p>
</blockquote>
<p>See examples below:</p>
<pre><code>kubectl patch deploy deploy1 deploy2 --type json -p='[{&quot;op&quot;: &quot;replace&quot;, &quot;path&quot;: &quot;/spec/template/spec/containers/0/resources/limits/memory&quot;, &quot;value&quot;:&quot;120Mi&quot;}]'
</code></pre>
<p>or:</p>
<pre><code>kubectl patch deploy $(kubectl get deploy -o go-template --template '{{range .items}}{{.metadata.name}}{{&quot; &quot;}}{{end}}') --type json -p='[{&quot;op&quot;: &quot;replace&quot;, &quot;path&quot;: &quot;/spec/template/spec/containers/0/resources/limits/memory&quot;, &quot;value&quot;:&quot;120Mi&quot;}]'
</code></pre>
<p>For further reference see <a href="https://kubernetes.io/docs/tasks/manage-kubernetes-objects/update-api-object-kubectl-patch/" rel="noreferrer">this doc</a>.</p>
<ol start="2">
<li>You can add proper labels into deployment via <a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#-em-resources-em-" rel="noreferrer">kubectl set</a> command:</li>
</ol>
<hr />
<pre><code>kubectl set resources deployment -l key=value --limits memory=120Mi
</code></pre>
<ol start="3">
<li>Also, you can use some additional CLI like <code>sed</code>, <code>awk</code> or <code>xargs</code>. For example:</li>
</ol>
<hr />
<pre><code>kubectl get deployments -o name | sed -e 's/.*\///g' | xargs -I {} kubectl patch deployment {} --type=json -p='[{&quot;op&quot;: &quot;replace&quot;, &quot;path&quot;: &quot;/spec/template/spec/containers/0/imagePullPolicy&quot;, &quot;value&quot;: &quot;Always&quot;}]'
</code></pre>
<p>or:</p>
<pre><code>kubectl get deployments -o name | awk '{print $1 }' | xargs kubectl patch deployment $0  -p &quot;{\&quot;spec\&quot;:{\&quot;template\&quot;:{\&quot;metadata\&quot;:{\&quot;annotations\&quot;:{\&quot;date\&quot;:\&quot;`date +'%s'`\&quot;}}}}}&quot;
</code></pre>
<ol start="4">
<li>It is also worth noting that configuration files should be stored in version control before being pushed to the cluster. See the <a href="https://kubernetes.io/docs/concepts/configuration/overview/" rel="noreferrer">Configuration Best Practices</a> for more details.</li>
</ol>
