基于 k8s-prometheus-adapter 的 custom metrics api 部署好了,请求下面的 url 有正常响应
kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1/" | jq .
但通过下面的命令获取 http_requests 指标却出错:
kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1/namespaces/production/pods/*/http_requests" | jq .
Error from server (NotFound): the server could not find the metric http_requests for pods
请问如何解决?
通过 prometheus 所在的命名空间 monitoring 可以获取到 prometheus_http_requests 指标数据
kubectl get --raw /apis/custom.metrics.k8s.io/v1beta1/namespaces/monitoring/pods/*/prometheus_http_requests | jq .
但换成应用在命名空间 production 获取不到 prometheus_http_requests 指标数据,items 为空。
$ kubectl get --raw /apis/custom.metrics.k8s.io/v1beta1/namespaces/production/pods/*/prometheus_http_requests | jq .
{
"kind": "MetricValueList",
"apiVersion": "custom.metrics.k8s.io/v1beta1",
"metadata": {
"selfLink": "/apis/custom.metrics.k8s.io/v1beta1/namespaces/production/pods/%2A/prometheus_http_requests"
},
"items": []
}
通过 kubectl logs kube-controller-manager-k8s-master1 -n kube-system | tail
查看 controller manager 的日志,发现下面的错误:
unable to get metric http_requests: unable to fetch metrics from custom metrics API: the server could not find the metric http_requests for pods
stackoverflow 上的相同问题(未解决):Prometheus' http_request custom-metric not working in Kubernetes
– dudu 4年前访问 prometheus 控制台查询 prometheus_http_requests_total 指标发现的确只有 monitoring 命名空间下的 pod
– dudu 4年前