Reputation: 101
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.
Thanks for your help in advance.
Upvotes: 8
Views: 9372
Reputation: 13898
There are few things to point out here:
Update field(s) of a resource using strategic merge patch, a JSON merge patch, or a JSON patch.
JSON and YAML formats are accepted.
See examples below:
kubectl patch deploy deploy1 deploy2 --type json -p='[{"op": "replace", "path": "/spec/template/spec/containers/0/resources/limits/memory", "value":"120Mi"}]'
or:
kubectl patch deploy $(kubectl get deploy -o go-template --template '{{range .items}}{{.metadata.name}}{{" "}}{{end}}') --type json -p='[{"op": "replace", "path": "/spec/template/spec/containers/0/resources/limits/memory", "value":"120Mi"}]'
For further reference see this doc.
kubectl set resources deployment -l key=value --limits memory=120Mi
sed
, awk
or xargs
. For example: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"}]'
or:
kubectl get deployments -o name | awk '{print $1 }' | xargs kubectl patch deployment $0 -p "{\"spec\":{\"template\":{\"metadata\":{\"annotations\":{\"date\":\"`date +'%s'`\"}}}}}"
Upvotes: 12
Reputation: 54249
You can use kustomize's "components" system if you want to set them all to the same thing. But that's unlikely. Better solution is probably write a little Python (or whatever lang you prefer) script to modify all the YAML files and push them back into source control.
Upvotes: 0