简体   繁体   English

kubernetes hpa 中外部指标的值很奇怪

[英]value of external metrics is weird in kubernetes hpa

I'm studying kubernetes and testing some example.我正在学习 kubernetes 并测试一些示例。

I got a problem with applying external metrics to hpa.我在将外部指标应用于 hpa 时遇到问题。

i made a external metrics with prometheus adapter.我用普罗米修斯适配器制作了一个外部指标。

so I can get external metrics using所以我可以使用外部指标

kubectl get --raw /apis/external.metrics.k8s.io/v1beta1/

command.命令。

result is below.结果如下。

{"kind":"APIResourceList","apiVersion":"v1","groupVersion":"external.metrics.k8s.io/v1beta1","resources":[{"name":"redis_keys","singularName":"","namespaced":true,"kind":"ExternalMetricValueList","verbs":["get"]}]}

and i can get metrics value using我可以使用

kubectl get --raw /apis/external.metrics.k8s.io/v1beta1/namespaces/default/redis_keys

command.命令。

result is below.结果如下。

{"kind":"ExternalMetricValueList","apiVersion":"external.metrics.k8s.io/v1beta1","metadata":{"selfLink":"/apis/external.metrics.k8s.io/v1beta1/namespaces/default/redis_keys"},"items":[{"metricName":"redis_keys","metricLabels":{},"timestamp":"2020-10-28T08:39:09Z","value":"23"}]}

and i applied the metric to hpa.我将该指标应用于 hpa。

below is hpa configuration.下面是hpa配置。

apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: taskqueue-autoscaler
spec:
  scaleTargetRef:
          #apiVersion: extensions/v1beta1
    apiVersion: apps/v1
    kind: Deployment
    name: taskqueue-consumer
  minReplicas: 1
  maxReplicas: 10
  metrics:
  - type: External
    external:
      metricName: redis_keys
      targetAverageValue: 20

after mading hpa,制作hpa后,

i tested this command.我测试了这个命令。

kubectl get hpa

and result is weird.结果很奇怪。

NAME                   REFERENCE                       TARGETS           MINPODS   MAXPODS   REPLICAS   AGE
taskqueue-autoscaler   Deployment/taskqueue-consumer   11500m/20 (avg)   1         10        2          63m

i think it's value(11500m) is wrong because result of query value is 23.我认为它的值(11500m)是错误的,因为查询值的结果是 23。

Where should i see in this case?在这种情况下我应该在哪里看?

Actually it's right, but its also complicated because it gets into a couple of different things with the HPA resource that are not immediately obvious.实际上它是对的,但它也很复杂,因为它涉及到 HPA 资源的几个不同的事情,这些事情不是很明显。 So I will tackle explaining this one thing at a time.所以我将一次解释这一件事。

First, the units of measurement.第一,计量单位。 The Metrics API will try to return whole units when possible, but does return milli-units as well, which can result in the above. Metrics API 将在可能的情况下尝试返回整数单位,但也会返回毫单位,这可能会导致上述情况。 Really, what you are seeing is 11.5 converted to 11500m, but the two are the same.真的,你看到的是11.5转换成11500m,但两者是一样的。 Check out this link on the "Quantities" of HPA metrics that covers it a bit more.HPA 指标“数量”上查看此链接,了解更多。

Next, you are seeing two replicas at the moment with a value from the Metrics API of 23. Since you have set the metric to be the AverageValue of the External Metric, it is dividing the value of the metric by the number of replicas in the cluster to result in 11.5 or 11500m when you view the HPA resource.接下来,您现在看到两个副本,其 Metrics API 的值为 23。由于您已将度量设置为外部度量的 AverageValue,因此它将度量值除以当您查看 HPA 资源时,集群会导致 11.5 或 11500m。 This explains why you are seeing only 2 replicas, while the value of the metric is "above" your threshold.这解释了为什么您只看到 2 个副本,而指标的值“高于”您的阈值。 Check out this link on Autoscaling with Multiple & Custom metrics, specifically the section about "Object" metrics .查看有关使用多个和自定义指标进行自动缩放的链接,特别是有关“对象”指标的部分 And lower down the page they slip in this line regarding External Metrics, confirming why you are seeing the above.并降低他们在有关外部指标的这一行中滑动的页面,确认您为什么会看到上述内容。

External metrics support both the Value and AverageValue target types, which function exactly the same as when you use the Object type.外部指标同时支持 Value 和 AverageValue 目标类型,其功能与您使用 Object 类型时的功能完全相同。

Hope this helps and a few tweaks should make it line up better with your expectations.希望这会有所帮助,并进行一些调整使其更符合您的期望。 Good luck out there!祝你好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM