首页 > 解决方案 > Horizo​​ntalPodAutoscaler 基于自定义指标的缩放 - 节点池级别指标

问题描述

我目前正在尝试设置 GKE 集群并HorizontalPodAutoscaler根据自定义指标(GPU 消耗)配置一个。我有两个节点池,我想根据每个节点的平均 GPU 消耗水平扩展它们 node_pool。我已经像这样配置了两个相同的 HPA:

apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: ner
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: ner
  minReplicas: 1
  maxReplicas: 10
  metrics:
    - type: External
      external:
        metric:
          name: kubernetes.io|container|accelerator|duty_cycle
        target:
          type: AverageValue
          averageValue: 60

我只替换了,scaleTargetRef但事实证明这个指标似乎是在集群级别聚合的。我已经仔细检查过scaleTargetRef是否正确定义。

有没有办法按container_nameor过滤指标node_pool?任何其他建议都会很棒!

标签: kubernetesgoogle-kubernetes-engine

解决方案


因此,我认为您正在为您的 k8 集群寻找指标,尤其是通过container_nameor node_pool

您可以在 HPA 对象中使用五种类型的指标(autoscaling/v2beta2)

k explain HorizontalPodAutoscaler.spec.metrics.type  --api-version=autoscaling/v2beta2

编辑更新


apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: ner
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: ner
  minReplicas: 1
  maxReplicas: 10
  metrics:
    - type: ContainerResource
      containerResource:
        name: gpu
        container: your-application-container
        target:
          type: Utilization
          averageUtilization: 60

编辑更新

对于具有 Cloud Monitoring 指标的 GKP Autoscaling 部署


推荐阅读