首页新闻找找看学习计划

k8s 使用 Prometheus custom metrics 配置 HPA 自动伸缩遇到问题

0
悬赏园豆:50 [已解决问题] 解决于 2020-01-12 22:15

使用下面的 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

k8s
dudu的主页 dudu | 高人七级 | 园豆:39099
提问于:2020-01-12 21:40
< >
分享
最佳答案
0

在 github 上找到了答案,原来是配置写法改了,正确的写法是

  metrics:
    - type: Pods
      pods:
        metric:
          name: http_requests
        target:
          type: AverageValue
          averageValue: 100
dudu | 高人七级 |园豆:39099 | 2020-01-12 22:14
dudu | 园豆:39099 (高人七级) | 2020-01-12 22:25
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册