昨天晚上通过压测验证了 HPA 部署成功了。
所使用的 HPA 配置文件如下:
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: blog-web
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: blog-web
minReplicas: 2
maxReplicas: 8
metrics:
- type: Pods
pods:
metric:
name: http_requests_received
target:
type: AverageValue
averageValue: 10
最小 pod 副本数是 2 ,最大 pod 副本数是 8 ,基于 http_requests_received 指标(对应的就是 QPS )进行伸缩,当指标平均值高于 10 时,自动进行扩容。
使用下面的压测命令发起了 100 个并发请求。
hey -c 100 -z 5m http://hostname
随后 HPA 自动将对应的 pod 副本由 2 个扩容至 8 个。
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
blog-web Deployment/blog-web 10253m/10 2 8 8 4d23h
上面的 http_requests_received 指标是 HPA 通过 custom-metrics-api