← All posts

Kubernetes – Patch number of replicas for HPA

Need to change the min or max replicas on a HorizontalPodAutoscaler? The quickest way is kubectl patch. No editing YAML files — just one command.

Change minReplicas

Here’s how to set minReplicas to 2:

kubectl patch hpa my-app -p '{"spec":{"minReplicas":2}}'

Change maxReplicas

And here’s maxReplicas set to 4:

kubectl patch hpa my-app -p '{"spec":{"maxReplicas":4}}'

Do it for lots of HPAs at once

Got many HPAs to update? Wrap it in a simple loop:

for i in `kubectl get hpa -o name`; do kubectl patch $i -p '{"spec":{"maxReplicas":4}}'; done;