具有自定义指标的HPA

时间:2020-04-30 15:04:17

标签: google-kubernetes-engine prometheus hpa

我遇到了两种不同的方法来扩展特定指标,我想知道有什么区别,以及我是否有这种区别。

我在GKE上进行了一个部署,包括从应用程序中抓取特定的度量并将其导出到堆栈驱动程序。使用prometheus-sd小车。 指标在堆栈驱动程序上显示为custom.googleapis.com/dummy/foo

现在,通常当我为自定义指标执行HPA时,我会像以下这样使用它:

apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: custom-metric-prometheus-sd
  namespace: default
spec:
  scaleTargetRef:
    apiVersion: apps/v1beta1
    kind: Deployment
    name: custom-metric-prometheus-sd
  minReplicas: 1
  maxReplicas: 5
  metrics:
  - type: External
    external:
      metricName: "custom.googleapis.com|dummy|foo"
      targetAverageValue: 20

现在,相同的hpa也可以使用Pod指标方法工作。喜欢:

apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: custom-metric-prometheus-sd
  namespace: default
spec:
  scaleTargetRef:
    apiVersion: apps/v1beta1
    kind: Deployment
    name: custom-metric-prometheus-sd
  minReplicas: 1
  maxReplicas: 5
  metrics:
  - type: Pods
    pods:
      metricName: "custom.googleapis.com|dummy|foo"
      targetAverageValue: 20

它的工作原理相同。 我了解到,使用Pod Metrics时,HPA将从所有Pod中获取指标,并将计算平均值,并将其与目标值进行比较,以确定副本数。 其基本与在外部指标上使用targetAverageValue相同。 因此,就我而言,两者基本相同,对吗? 在性能,延迟方面还有其他不同吗?

谢谢 陈

1 个答案:

答案 0 :(得分:0)

是的,您说得很对。您在问题中显示的指标将起作用。

再深入一点,阅读有关指标类型的文档: Kubernetes.io: Docs: Reference: Kubernetes API: v1.18: metricspec-v2beta1-autoscaling

ExternalMetricSource-外部是指未与任何Kubernetes对象关联的全局指标。它允许基于来自群集外部运行的组件的信息(例如,云消息传递服务中的队列长度或来自群集外部运行的loadbalancer的QPS)进行自动缩放。

PodsMetricSource-Pod是指描述当前规模目标中每个Pod的指标(例如,每秒处理的事务数)。这些值将在与目标值进行比较之前进行平均。

请记住,此参考适用于api版本1.18。请使用适合您用例的版本。

文档显示它们被设计为不同的指标,但是可以像您一样使用。

除了描述之外,还有一个区别是度量标准:

  • External具有以下字段:
    • metricName
    • metricSelector
    • targetAverageValue
    • targetValue
  • Pods具有以下字段:
    • metricName
    • metricSelector
    • targetAverageValue

如上所示,Pods指标没有 targetValue 字段。

每种类型的指标都有其自己的属性集,其中某些属性在使用时给出相同的结果。

如果您有任何疑问,请告诉我。