gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 12:36:12 26 4
gpt4 key购买 nike

我已将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必须能够读取自定义指标。

最佳答案

回答

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

由于您的指标来自您要自动缩放的“部署” Pane ,因此应使用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的设计文档。

    关于kubernetes - HPA无法从Prometheus适配器获取自定义指标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55725014/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com