Google Cloud Platform for Architects
上QQ阅读APP看书,第一时间看更新

Scaling pods with the horizontal pod autoscaler

It is also possible in recent versions of Kubernetes to scale pods (rather than nodes). This also allows us to scale down to a node pool of zero, that is to scale down to zero if there is no demand for the service while also retaining the ability to scale up with demand.

Combining the two, that is, scaling in both directions allows you to make your application truly elastic. Remember that pods are a Kubernetes concept, so unsurprisingly, such autoscaling is carried out using kubectl rather than gcloud:

  1. To do this, you need to apply a Horizontal Pod Autoscaler (HPA) by using the kubectl autoscale command. The max flag is mandatory, while the min flag is optional. The cpu-percent indicates total CPU utilization:
kubectl autoscale deployment my-app --max=6 --min=4 --cpu-percent=50  
  1. To check any HPA, use the kubectl describe command:
kubectl describe hpa [NAME-OF-HPA] 
  1. Similarly, use the kubectl delete command to remove HPAs:
kubectl delete hpa [NAME-OF-HPA]