~/snippets/k8s_update_multiple_crs
Published on

Update multiple K8s CRs (kubectl)

136 words1 min read

Let's say, you have a Custom Resource Definition (CRD) called job that has a priority field within the Spec. If you needed to update a lot of Custom Resources (CRs) at one time, for example to change the priority from Low to High, you could do so using a bash loop, but why bother when kubectl offers us a patch method.

To expand on our example; to update our jobs to have a high priority:

kubectl patch jobs {space delimited list of job names} --type=merge -p '{"spec": { "priority": "High" }}'