使用下面的 yaml 配置
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: blog-web
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: blog-web
minReplicas: 5
maxReplicas: 12
metrics:
- type: Pods
pods:
metricName: http_requests
targetAverageValue: 100
用 kubectl apply -f hpa-blog-web.yaml 命令部署时却报错
error: error validating "hpa-blog-web.yaml": error validating data: [ValidationError(HorizontalPodAutoscaler.spec.metrics[0].pods): unknown field "metricName" in io.k8s.api.autoscaling.v2beta2.PodsMetricSource, ValidationError(HorizontalPodAutoscaler.spec.metrics[0].pods): unknown field "targetAverageValue" in io.k8s.api.autoscaling.v2beta2.PodsMetricSource, ValidationError(HorizontalPodAutoscaler.spec.metrics[0].pods): missing required field "metric" in io.k8s.api.autoscaling.v2beta2.PodsMetricSource, ValidationError(HorizontalPodAutoscaler.spec.metrics[0].pods): missing required field "target" in io.k8s.api.autoscaling.v2beta2.PodsMetricSource]; if you choose to ignore these errors, turn validation off with --validate=false
请问如何解决?
注: Kubernetes 版本是 1.17.0
在 github 上找到了答案,原来是配置写法改了,正确的写法是
metrics:
- type: Pods
pods:
metric:
name: http_requests
target:
type: AverageValue
averageValue: 100
另外一个相关 issue :Pods metric setting not consistent in HPA walkthrough