Kubenetes: change hpa min-replica

8/12/2018

I have Kubernetes cluster hosted in Google Cloud. I created a deployment and defined a hpa rule for it:

kubectl autoscale deployment my_deployment --min 6 --max 30 --cpu-percent 80

I want to run a command that editing the --min value, without remove and re-create a new hpa rule. Something like:

$ kubectl autoscale deployment my_deployment --min 1 --max 30
Error from server (AlreadyExists): horizontalpodautoscalers.autoscaling "my_deployment" already exists

Is this possible to edit hpa (min, max, cpu-percent, ...) on command line?

-- No1Lives4Ever
google-cloud-platform
kubectl
kubernetes

1 Answer

8/12/2018

Is this possible to edit hpa (min, max, cpu-percent, ...) on command line?

They are editable just as any other resource is, though either kubectl edit hpa $the_hpa_name for an interactive edit, or kubectl patch hpa $the_hpa_name -p '{"spec":{"minReplicas": 1}}' for doing so in a "batch" setting.

If you don't know the $the_hpa_name, you can get a list of them like any other resource: kubectl get hpa, and similarly you can view the current settings and status with kubectl get -o yaml hpa $the_hpa_name (or even omit $the_hpa_name to see them all, but that might be a lot of text, depending on your cluster setup).

-- mdaniel
Source: StackOverflow