Kubernetes HPA获取自定义指标的当前值错误

时间:2018-04-13 12:27:50

标签: docker kubernetes autoscaling google-kubernetes-engine

当实际指标值低于132500m / 500时(根据普罗米修斯),HPA状态会显示100/500

$ kubectl get hpa -n frontend --context testing
NAME       REFERENCE              TARGETS                               MINPODS   MAXPODS   REPLICAS   AGE
frontend   Deployment/streaming   50237440 / 629145600, 132500m / 500   2         5         2          4d

HPA清单是:

---
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: frontend
  namespace: streaming
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: streaming
  minReplicas: 2
  maxReplicas: 5
  metrics:
  - type: Pods
    pods:
      metricName: redis_memory_used_rss_bytes
      targetAverageValue: 629145600
  - type: Pods
    pods:
      metricName: redis_db_keys
      targetAverageValue: 500

它应该打印正常结果,例如:

$ kubectl get hpa -n streaming --context streaming-eu
NAME       REFERENCE              TARGETS                               MINPODS   MAXPODS   REPLICAS   AGE
frontend   Deployment/streaming   50237440 / 629145600, 87 / 500   2         5         2          4d

问题在于132500m值,这是错误的(普罗米修斯查询报告正常值)。由于HPA没有扩展到该指标,所以它认为它的价值有些不同,我想。

使用oliver006/redis_exporter及其指标作为HPA的自定义Pod指标来重现此问题。

Kubernetes版

Client Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.6", GitCommit:"6260bb08c46c31eea6cb538b34a9ceb3e406689c", GitTreeState:"clean", BuildDate:"2017-12-21T06:34:11Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}`
Server Version: version.Info{Major:"1", Minor:"9+", GitVersion:"v1.9.4-gke.1", GitCommit:"10e47a740d0036a4964280bd663c8500da58e3aa", GitTreeState:"clean", BuildDate:"2018-03-13T18:00:36Z", GoVersion:"go1.9.3b4", Compiler:"gc", Platform:"linux/amd64"}

云提供商

GKE 1.9.4

1 个答案:

答案 0 :(得分:2)

我认为这是指标转换问题。

以下是来自相关问题的贡献者的好comment,但它是关于http_requests指标:

  

如果查看Prometheus适配器的文档,您会看到所有累积(计数器)指标都转换为费率指标,因为HPA的算法与直接扩展累积指标基本上不兼容(直接扩展累积指标)一般来说没有多大意义。)

     

在您的情况下,您的http_requests_total正在转换为http_requests,因此在使用Prometheus适配器时,它将始终显示为来自指标API的毫秒请求。

所以,在你的情况下,它返回的东西像132500毫安。只需将值除以1000即可得到正确的平均值。