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

毕业设计客栈 毕业设计 1

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

回复

共1条回复 我来回复
  • 代码港湾
    这个人很懒,什么都没有留下~
    评论

    配置写法改了,正确的写法是

      metrics:
        - type: Pods
          pods:
            metric:
              name: http_requests
            target:
              type: AverageValue
              averageValue: 100
    
    0条评论

发表回复

登录后才能评论