1

我遇到了两种不同的方法来衡量一个特定的指标,我想知道有什么区别,在我的情况下是否有这种情况。

我在 GKE 上有一个部署,包括从应用程序中抓取特定指标并将其导出到 stackdriver。使用 prometheus-to-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 基本相同。所以,就我而言,两者的作用基本相同,对吧?在性能,延迟等方面有什么不同吗?

谢谢陈

4

1 回答 1

1

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

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

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

PodsMetricSource - pods 是指描述当前缩放目标中每个 pod 的指标(例如,每秒处理的事务数)。在与目标值进行比较之前,这些值将被一起平均。

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

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

除了描述之外,区分它们的另一件事是该指标:

  • External有字段:
    • metricName
    • metricSelector
    • targetAverageValue
    • targetValue
  • Pods有字段:
    • metricName
    • metricSelector
    • targetAverageValue

正如您在上面看到的,该Pods指标没有 targetValue字段。

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

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

于 2020-05-07T15:47:07.807 回答