kubernetes全自动弹性伸缩组件
目标
- 使用容器完成 metrics-server 部署
- 演示 Horizontal Pod Autoscaling (pod 自动缩放)
部署 metrics-server 服务
- Horizontal Pod Autoscaler(HPA)控制器用于实现基于CPU使用率进行自动Pod伸缩的功能。
- HPA控制器基于Master的kube-controller-manager服务启动参数–horizontal-pod-autoscaler-sync-period定义是时长(默认30秒),周期性监控目标Pod的CPU使用率,并在满足条件时对ReplicationController或Deployment中的Pod副本数进行调整,以符合用户定义的平均Pod CPU使用率。
- 在新版本的kubernetes中 Pod CPU使用率不在来源于heapster,而是来自于metrics-server
- 官网原话是
The --horizontal-pod-autoscaler-use-rest-clients is true or unset. Setting this to false switches to Heapster-based autoscaling, which is deprecated.
- yml 文件来自于github https://github.com/kubernetes-incubator/metrics-server/tree/master/deploy/1.8+
- /etc/kubernetes/pki/front-proxy-ca.pem 文件来自于部署kubernetes集群
- 需要对yml文件进行修改才可使用 改动如下
- 利用Flags-horizontal-pod-autoscaler-sync-period确定hPa对于Pods组指标的监控频率。默认的周期为30秒。
- 两次扩展操作之间的默认间隔为3分钟,可以Flags来控制-horizontal-pod-autoscaler-upscale-delay
- 两个缩小操作之间的默认间隔为5分钟,同样可以通过Flags来控制-horizontal-pod-autoscaler-downscale-delay
|
|
- 这里将github提供的多个文件合并为一个方便一些
- kubectl apply -f metrics-server.yml 进行部署
|
|
- 测试metrics-server 是否部署成功
|
|
部署HPA实验案列
|
|
参考资料
- 原文作者:青木
- 原文链接:https://goudai.github.io/posts/kubernetes-metrics-server/
- 版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可,非商业转载请注明出处(作者,原文链接),商业转载请联系作者获得授权。