(十一)基于metric server的自动伸缩hpa
2019-05-03 20:42
197 查看
概念
hpa功能: 能根据pod的cpu丶内存以及其它指标自动伸缩pod副本数量, 该指标由metrics-service和custom-metrics-apiserver提供 hpa版本: 通过kubectl api-versions查看 autoscaling/v1 autoscaling/v2beta1 由metrics-service提供, 仅支持cpu指标来弹性伸缩 autoscaling/v2beta2 由custom-metrics-apiserver来提供, 支持内存网络cpu等指标
实验目标: 创建一个pod,然后创建一个hpa监控pod的cpu使用率, 再对实施压测, 查看hpa是否根据pod的使用率伸缩pod副本
创建pod
kubectl run hpa-test --image=nginx:1.11 --requests=cpu=200m --expose --port=80 -o yaml --dry-run kubectl run hpa-test --image=nginx:1.11 --requests=cpu=200m --expose --port=80
创建hpa 超过cpu使用50% 最少创建一个pod, 最多创建10个pod
kubectl autoscale deployment hpa-test --cpu-percent=50 --min=1 --max=10 -o yaml --dry-run kubectl autoscale deployment hpa-test --cpu-percent=50 --min=1 --max=10
启动一个程序进行压力测试
kubectl run -i --rm --tty load-generator --image=busybox /bin/sh #while true; do wget -q -O- http://hpa-test.default.svc.cluster.local; done
过一段时间查看 cpu超高, 自动扩展pod
停止压力测试,过一段时间自动减少 貌似我等了很久
扩展:同时针对cpu和内存设置, api版本: autoscaling/v2beta2
apiVersion: autoscaling/v2beta1 kind: HorizontalPodAutoscaler metadata: creationTimestamp: null name: hpa-test spec: maxReplicas: 10 minReplicas: 1 scaleTargetRef: apiVersion: extensions/v1beta1 kind: Deployment name: hpa-test metrics: - type: Resource resource: name: cpu targetAverageUtilization: 50 - type: Resource resource: name: memory targetAverageValue: 50Mi
相关文章推荐
- 基于Custom-metrics-apiserver实现Kubernetes的HPA(内含踩坑)
- 一种基于Qt的可伸缩的全异步C/S架构server实现(二) 网络传输
- 基于Prometheus,Alermanager实现Kubernetes自动伸缩
- 一种基于Qt的可伸缩的全异步C/S架构server实现(五) 单层无中心集群
- 一款负载均衡、监控和自动伸缩的解决方案——为基于AWS API的私有云而建
- (基于Jenkins + SVN + Ant + Weblogic Server的)应用程序自动(/一键)部署的设想
- 基于公钥认证方式的 OpenSSH Server 自动登录完全手册
- 基于Prometheus,Alermanager实现Kubernetes自动伸缩
- 一种基于Qt的可伸缩的全异步C/S架构server实现(一) 综述
- MySQL bug:server-id默认被自动置为1
- C# QQ机器人(自动应答) (基于WebQQ)
- 基于Eclipse Maven的Spring4/Spring-MVC/Hibernate4整合之十一:利用拦截器控制访问权限
- Ubuntu 9.10 Server 配置基于SSL的Subversion
- 一种基于直方图均衡化的自动化立体仓库储位自动分配算法简述
- 基于容器的自动构建——Docker在美团的应用
- 基于MINA实现server端心跳检测(KeepAliveFilter)
- 基于 PHP & MySQL 搭建OAuth Server