如何在Kubernetes中检查外部度量数据



我正在使用DirectXMan12/k8s prometheus adapte将外部度量从prometheus推送到Kubernetes。

推送外部度量后,我如何验证数据是k8s?

当我点击kubectl get--raw/apis/external.metrics.k8s.io/v1beta1|jq时,我得到了以下结果,但在那之后,我不知道如何获取实际的度量值

{
"kind": "APIResourceList",
"apiVersion": "v1",
"groupVersion": "external.metrics.k8s.io/v1beta1",
"resources": [
{
"name": "subscription_back_log",
"singularName": "",
"namespaced": true,
"kind": "ExternalMetricValueList",
"verbs": [
"get"
]
}]
}

每个实例都会获取实际度量值,例如,您附加的度量是namespaced: true,假设该度量是针对pod的,则可以在访问实际数据

kubectl get --raw "/apis/external.metrics.k8s.io/v1beta1/namespaces/wanted_namepsace/pods/*/subscription_back_log" | jq '.'

(或指定吊舱名称而非*(

如果你想让HPA读取你的度量,配置是(例如(

apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: your-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: your-pod
minReplicas: 1
maxReplicas: 10
metrics:
- pods:
metricName: subscription_back_log
targetAverageValue: 10000
type: Pods

度量是按名称空间设置的,因此您需要将名称空间添加到URL中。与另一个答案相反,我相信你不需要在URL中包含pod。这是一个外部度量。外部度量与任何kubernetes对象都没有关联,因此只有命名空间就足够了:

  • /apis/external.metrics.k8s.io/v1beta1/namespaces/<namespace>/<metric_name>

这里有一个适用于我的例子,在我的设置中使用外部度量:

$ kubectl get --raw /apis/external.metrics.k8s.io/v1beta1 | jq                                               
{
"kind": "APIResourceList",
"apiVersion": "v1",
"groupVersion": "external.metrics.k8s.io/v1beta1",
"resources": [
{
"name": "redis_key_size",
"singularName": "",
"namespaced": true,
"kind": "ExternalMetricValueList",
"verbs": [
"get"
]
}
]
}
$ kubectl get --raw /apis/external.metrics.k8s.io/v1beta1/namespaces/default/redis_key_size
{
"kind": "ExternalMetricValueList",
"apiVersion": "external.metrics.k8s.io/v1beta1",
"metadata": {},
"items": [
{
"metricName": "redis_key_size",
"metricLabels": {
"key": "..."
},
"timestamp": "2021-10-07T09:00:01Z",
"value": "0"
},
...
]
}

相关内容

  • 没有找到相关文章

最新更新