简体   繁体   English

HPA无法从Prometheus适配器获取自定义指标

[英]HPA is unable to fetch custom metrics from prometheus adapter

I have configured Prometheus-adapter to fetch custom metrics from Prometheus. 我已将Prometheus-adapter配置为从Prometheus获取自定义指标。 When I execute the command: kubectl get --raw /apis/custom.metrics.k8s.io/v1beta1 当我执行命令时: kubectl get --raw /apis/custom.metrics.k8s.io/v1beta1

Following is the result. 以下是结果。

 {
      "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"
      ]
    },

My HPA configuration is as follows: 我的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 results in unknown. Hpa导致未知。 Not sure why it is not able to fetch metrics. 不知道为什么它无法获取指标。

Hpa must be able to read the custom metrics. Hpa必须能够读取自定义指标。

Answer 回答

Since your HPA configuration declares the metric as type: External , the HPA tries to fetch it from the External Metrics API ( /apis/custom.metrics.k8s.io ), but the Prometheus Adapter exposes it on the Custom metrics API ( /apis/custom.metrics.k8s.io ). 由于您的HPA配置将度量标准声明为type: External ,因此HPA尝试从External Metrics API( /apis/custom.metrics.k8s.io )中获取它,但是Prometheus适配器将其公开在Custommetrics API( /apis/custom.metrics.k8s.io )。

Since your metric comes from the Pods of the Deployment that you're trying to autoscale, you should use the Pods metric type. 由于您的指标来自您要自动缩放的“部署的Pod”,因此应使用Pods指标类型。 So, change your HPA configuration to: 因此,将您的HPA配置更改为:

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

Background 背景

You can see all the available HPA metric types and their usages here: 您可以在此处查看所有可用的HPA度量标准类型及其用法:

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

There are four metric types, and they map to the various metric APIs as follows: 有四种度量标准类型,它们映射到以下各种度量标准API:

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

See HPA docs , and design documents for Resource Metrics API , Custom Metrics API , and External Metrics API . 请参阅HPA文档 ,以及有关资源指标API自定义指标API外部指标API的设计文档。

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

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