我已经配置了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必须能够读取自定义指标。
答案 0 :(得分:0)
由于您的HPA配置将度量标准声明为type: External
,因此HPA尝试从外部度量标准API(/apis/custom.metrics.k8s.io
)中获取该度量标准,但是Prometheus适配器在自定义度量标准API({{ 1}})。
由于您的指标来自您尝试自动扩展的“部署”窗格,因此应使用/apis/custom.metrics.k8s.io
指标类型。因此,将您的HPA配置更改为:
Pods
您可以在此处查看所有可用的HPA度量标准类型及其用法:
# ...
metrics:
- type: Pods
pods:
metricName: fs_writes_merged
targetValue: 100
有四种度量标准类型,它们映射到以下各种度量标准API:
kubectl explain --api-version=autoscaling/v2beta1 hpa.spec.metrics
:资源指标API(Resource
)/apis/metrics.k8s.io/v1beta1
:自定义指标API(Pods
)/apis/custom.metrics.k8s.io/v1beta1
:自定义指标API(Object
)/apis/custom.metrics.k8s.io/v1beta1
:外部指标API(External
)请参见HPA docs,并为Resource Metrics API,Custom Metrics API和External Metrics API设计文档。