Horizontal Pod Autoscaling可以根据CPU利用率自动伸缩一个Replication Controller、Deployment 或者Replica Set中的Pod数量,要使用Horizontal Pod Autoscaling,需要再集群中安装metrics-server,用来统计集群中resource 对硬件资源的占用
部署和运行apache服务器并将其暴露成为Kubernetes服务
1 | kubectl run webserver --image=httpd:latest --requests=cpu=200m --expose --port=80 |
当pod cpu资源 30% 时 Autoscale deployment
1 | kubectl autoscale deployment webserver --cpu-percent=30 --min=1 --max=10 |
查看hpa
pod 的cpu使用率获取比较慢,需要稍等一会,如果获取不到,要检查metrics-server是否正确安装
1 | $ [K8sDev] kubectl get hpa |
查看service
1 | $ [K8sDev] kubectl get service |
启动多个pod增加负载
1 | kubectl run loads --image=radial/busyboxplus:curl --replicas=3 --command -- sh -c "while true;do curl http://webserver.default;done" |
查看hpa cpu使用率,可以看到pod已经在自动伸缩了
1 | $ [K8sDev] kubectl get hpa |
删除loads ,观察webserver replicas
1 | $ [K8sDev] kubectl delete deployment loads |
- 本文作者: ChuLinx
- 本文链接: http://yoursite.com/2019/11/30/kubernetes1.14 水平自动伸缩pod/
- 版权声明: 本博客所有文章除特别声明外,均采用 MIT 许可协议。转载请注明出处!