【问题标题】:HPA is unable to fetch custom metrics from prometheus adapterHPA 无法从 prometheus 适配器获取自定义指标
【发布时间】:2019-09-07 13:12:59
【问题描述】:

我已将 Prometheus-adapter 配置为从 Prometheus 获取自定义指标。 当我执行命令时: kubectl get --raw /apis/custom.metrics.k8s.io/v1beta1

结果如下。

 {
      "name": "namespaces/envoy_http_ingress_http_downstream_cx_http1",
      "singularName": "",
      "namespaced": false,
      "kind": "MetricValueList",
      "verbs": [
        "get"
      ]
    },
    {
      "name": "namespaces/envoy_cluster_xds_cluster_upstream_cx_rx_bytes",
      "singularName": "",
      "namespaced": false,
      "kind": "MetricValueList",
      "verbs": [
        "get"
      ]
    },
    {
      "name": "jobs.batch/statsd_exporter_lines",
      "singularName": "",
      "namespaced": true,
      "kind": "MetricValueList",
      "verbs": [
        "get"
      ]
    },
    {
      "name": "pods/fs_writes_merged",
      "singularName": "",
      "namespaced": true,
      "kind": "MetricValueList",
      "verbs": [
        "get"
      ]
    },

我的HPA配置如下:

apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: scale
  namespace: default
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: billing-app
  minReplicas: 1
  maxReplicas: 10
  # targetCPUUtilizationPercentage: 50
  metrics:
    - type: External
      external:
        metricName: fs_writes_merged
        targetValue: 100

Hpa 结果未知。不知道为什么它无法获取指标。

Hpa 必须能够读取自定义指标。

【问题讨论】:

  • 你关注this guide了吗?
  • 是的,我关注了。
  • 如果您遵循上述指南,您应该在 HPA 定义中使用 type: Pod 而不是 type: External 作为指标类型(在此下方,键是 pods 而不是 external)。也许尝试改变它?

标签: kubernetes google-cloud-platform prometheus autoscaling


【解决方案1】:

回答

由于您的 HPA 配置将指标声明为 type: External,HPA 会尝试从外部指标 API (/apis/custom.metrics.k8s.io) 获取它,但 Prometheus 适配器在自定义指标 API (/apis/custom.metrics.k8s.io) 上公开它。

由于您的指标来自您尝试自动扩展的部署 Pod,因此您应该使用 Pods 指标类型。因此,将您的 HPA 配置更改为:

  # ...
  metrics:
    - type: Pods
      pods:
        metricName: fs_writes_merged
        targetValue: 100

背景

您可以在此处查看所有可用的 HPA 指标类型及其用法:

kubectl explain --api-version=autoscaling/v2beta1 hpa.spec.metrics

有四种指标类型,它们映射到各种指标 API,如下所示:

  • Resource:资源指标 API (/apis/metrics.k8s.io/v1beta1)
  • Pods:自定义指标 API (/apis/custom.metrics.k8s.io/v1beta1)
  • Object:自定义指标 API (/apis/custom.metrics.k8s.io/v1beta1)
  • External:外部指标 API (/apis/external.metrics.k8s.io/v1beta1)

参见HPA docs,以及Resource Metrics APICustom Metrics APIExternal Metrics API 的设计文档。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-19
    • 2020-12-15
    • 2021-04-12
    • 2021-06-08
    • 2020-08-27
    相关资源
    最近更新 更多