kubernetes HPA报告的外部指标值与端点值不同

ljsrvy3e  于 2023-03-29  发布在  Kubernetes
关注(0)|答案(1)|浏览(131)

我正在尝试使用外部指标来扩展具有HPA的部署。外部指标是从Prometheus中的指标创建的,并使用Prometheus适配器导出。
当我到达外部指标的端点时,我得到了正确的值,所以我相信到那时为止的一切(指标生成器,prometheus,prometheus适配器)都正常工作。

kubectl get --raw /apis/external.metrics.k8s.io/v1beta1/namespaces/default/queues_idle_agent_count | jq
{
  "kind": "ExternalMetricValueList",
  "apiVersion": "external.metrics.k8s.io/v1beta1",
  "metadata": {},
  "items": [
    {
      "metricName": "queues_idle_agent_count",
      "metricLabels": {},
      "timestamp": "2023-03-24T17:24:52Z",
      "value": "7"
    }
  ]
}

7是我有多少空闲代理的正确值。
然而,在我的HPA中没有显示该值:

❯ k describe hpa                                                                                         
Warning: autoscaling/v2beta2 HorizontalPodAutoscaler is deprecated in v1.23+, unavailable in v1.26+; use autoscaling/v2 HorizontalPodAutoscaler
Name:                                                buildkite-agent
Namespace:                                           default
Labels:                                              <none>
Annotations:                                         <none>
CreationTimestamp:                                   Fri, 24 Mar 2023 13:20:02 -0400
Reference:                                           Deployment/buildkite-agent
Metrics:                                             ( current / target )
  "queues_idle_agent_count" (target average value):  1 / 2
Min replicas:                                        3
Max replicas:                                        25
Deployment pods:                                     7 current / 7 desired
Conditions:
  Type            Status  Reason               Message
  ----            ------  ------               -------
  AbleToScale     True    ScaleDownStabilized  recent recommendations were higher than current one, applying the highest recent recommendation
  ScalingActive   True    ValidMetricFound     the HPA was able to successfully calculate a replica count from external metric queues_idle_agent_count(nil)
  ScalingLimited  False   DesiredWithinRange   the desired count is within the acceptable range
Events:
  Type    Reason             Age    From                       Message
  ----    ------             ----   ----                       -------
  Normal  SuccessfulRescale  2m45s  horizontal-pod-autoscaler  New size: 7; reason: All metrics below target

有趣的部分在这里:

Metrics:                                             ( current / target )
  "queues_idle_agent_count" (target average value):  1 / 2

我的目标值是2,但它报告当前值为1,而实际值为7。
我发现this问题与我的问题有关,但似乎这个问题只是一个缩放问题,而我的问题不是由于缩放。
我不确定为什么HPA报告的值不正确。
hpa.yaml

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: buildkite-agent
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: buildkite-agent
  minReplicas: 3
  maxReplicas: 25
  metrics:
  - type: External
    external:
      metric:
        name: queues_idle_agent_count
      target:
        type: AverageValue
        averageValue: 2
xe55xuns

xe55xuns1#

似乎传递度量的方式是value/n,其中n是最小副本,value是从度量接收的值。
这不是我认为的度量传递方式,但它可用于此用例。

相关问题