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

使用下面的 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
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.

用 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
  • 1.

请问如何解决?

注: Kubernetes 版本是 1.17.0

k8s
Kubernetes
2023-07-13 13:37:29
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
叶落风逝yzm

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

metrics:
    - type: Pods
      pods:
        metric:
          name: http_requests
        target:
          type: AverageValue
          averageValue: 100
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
分享
微博
QQ
微信
回复
2023-07-13 15:16:54
相关问题
k8s 集群 dns 解析问题
3091浏览 • 1回复 待解决
k8s 上部署 nodelocaldns 的问题
3742浏览 • 1回复 待解决
K8s 无法删除 namespace 的问题
2977浏览 • 1回复 待解决
k8s使用 coredns 重写主机名的问题
3101浏览 • 1回复 待解决
k8s 集群 coredns pod 部署异常
3324浏览 • 1回复 待解决
k8s强制删除所有Pending的po
8314浏览 • 1回复 待解决
如何在 k8s 上部署 Redis 服务?
4222浏览 • 1回复 待解决
K8S 如何删除 node有知道的吗?
3585浏览 • 1回复 待解决
k8s 在加入新 node 后的 pod 调度问题
2776浏览 • 1回复 待解决
k8s 部署 springboot 项目有懂的吗?
4217浏览 • 1回复 待解决
Redis集群和K8S集群有什么关联吗
4602浏览 • 1回复 待解决
ob是否支持k8s部署,有知道的吗?
5333浏览 • 2回复 待解决
K8s访问基于Linx环境的Ftp报错,求支援
4922浏览 • 1回复 待解决