<p>We have hundreds of deployment and in the config we have imagePullPolicy set as “ifnotpresent” for most of them and for few it is set to “always” now I want to modify all deployment which has <strong>ifnotpresent</strong> to <strong>always</strong>.</p>

<p>How can we achieve this with at a stroke?</p>

<p>Ex:</p>

<pre><code>kubectl get deployment -n test -o json | jq ‘.spec.template.spec.contianer[0].imagePullPolicy=“ifnotpresent”| kubectl -n test replace -f - 
</code></pre>

<p>The above command helps to reset it for one particular deployment.</p>

Nishanth
<p>Kubernetes doesn't natively offer mass update capabilities. For that you'd have to use other CLI tools. That being said, for modifying existing resources, you can also use the <code>kubectl patch</code> function.</p>

<p>The script below isn't pretty, but will update all deployments in the namespace.</p>

<pre><code>kubectl get deployments -o name | sed -e 's/.*\///g' | xargs -I {} kubectl patch deployment {} --type=json -p='[{"op": "replace", "path": "/spec/template/spec/containers/0/imagePullPolicy", "value": "Always"}]'
</code></pre>

<p>Note: I used <code>sed</code> to strip the resource type from the name as kubectl doesn't recognize operations performed on resources of type <code>deployment.extensions</code> (and probably others).</p>
