Kubernetes – Patch number of replicas for HPA

Patch minimum/maximum number of replicas in HPA can be done easily by using kubectl patch command

Patch minReplicas

For example, minReplicas to 2

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

Patch maxReplicas

For example, maxReplicas to 4

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

To work with multiple HPA

Again, wrap it in basic for loop

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