prometheus-adapter 使用的正确 prometheus URL 是啥

Posted

技术标签:

【中文标题】prometheus-adapter 使用的正确 prometheus URL 是啥【英文标题】:What is the correct prometheus URL to be used by prometheus-adapterprometheus-adapter 使用的正确 prometheus URL 是什么 【发布时间】:2021-06-23 02:08:30 【问题描述】:

我已经成功部署

prometheus 通过 helm 图表 kube-prometheus-stack (https://prometheus-community.github.io/helm-charts) prometheus-adapter via helm chart prometheus-adapter (https://prometheus-community.github.io/helm-charts)

使用带有轻微定制的默认配置。

我可以访问 prometheus、grafana 和 alertmanager,查询指标并查看精美的图表。

但是 prometheus-adapter 在启动时一直抱怨它无法访问/发现指标:

I0326 08:16:52.266095       1 adapter.go:98] successfully using in-cluster auth
I0326 08:16:52.330094       1 dynamic_serving_content.go:111] Loaded a new cert/key pair for "serving-cert::/var/run/serving-cert/tls.crt::/var/run/serving-cert/tls.key"
E0326 08:16:52.334710       1 provider.go:227] unable to update list of all metrics: unable to fetch metrics for query "namespace!=\"\",__name__!~\"^container_.*\"": bad_response: unknown response code 404

我在 prometheus-adapter Deployment 命令行参数中尝试了各种 prometheus URL,但问题或多或少是一样的。

例如我试过的一些网址是

--prometheus-url=http://prometheus-operated.prom.svc:9090

--prometheus-url=http://prometheus-kube-prometheus-prometheus.prom.svc.cluster.local:9090                                                                                                                                                                                                              

有以下服务/pods在运行:

$ kubectl -n prom get pods
NAME                                                     READY   STATUS    RESTARTS   AGE
alertmanager-prometheus-kube-prometheus-alertmanager-0   2/2     Running   0          16h
prometheus-adapter-76fcc79b7b-7xvrm                      1/1     Running   0          10m
prometheus-grafana-559b79b564-bh85n                      2/2     Running   0          16h
prometheus-kube-prometheus-operator-8556f58759-kl84l     1/1     Running   0          16h
prometheus-kube-state-metrics-6bfcd6f648-ms459           1/1     Running   0          16h
prometheus-prometheus-kube-prometheus-prometheus-0       2/2     Running   1          16h
prometheus-prometheus-node-exporter-2x6mt                1/1     Running   0          16h
prometheus-prometheus-node-exporter-bns9n                1/1     Running   0          16h
prometheus-prometheus-node-exporter-sbcjb                1/1     Running   0          16h

$ kubectl -n prom get services
NAME                                      TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)                      AGE
alertmanager-operated                     ClusterIP   None           <none>        9093/TCP,9094/TCP,9094/UDP   16h
prometheus-adapter                        ClusterIP   10.0.144.45    <none>        443/TCP                      16h
prometheus-grafana                        ClusterIP   10.0.94.160    <none>        80/TCP                       16h
prometheus-kube-prometheus-alertmanager   ClusterIP   10.0.0.135     <none>        9093/TCP                     16h
prometheus-kube-prometheus-operator       ClusterIP   10.0.170.205   <none>        443/TCP                      16h
prometheus-kube-prometheus-prometheus     ClusterIP   10.0.250.223   <none>        9090/TCP                     16h
prometheus-kube-state-metrics             ClusterIP   10.0.135.215   <none>        8080/TCP                     16h
prometheus-operated                       ClusterIP   None           <none>        9090/TCP                     16h
prometheus-prometheus-node-exporter       ClusterIP   10.0.70.247    <none>        9100/TCP                     16h

kubectl -n kube-system get deployment/metrics-server
NAME             READY   UP-TO-DATE   AVAILABLE   AGE
metrics-server   1/1     1            1           15d

使用以下值部署 Prometheus-adapter helm chart:

prometheus:
  url: http://prometheus-kube-prometheus-prometheus.prom.svc.cluster.local
certManager:
  enabled: true

我的设置中 prometheus-adapter--prometheus-url 的正确值是多少?

【问题讨论】:

后续问题是我看不到要用于 HPA 的自定义指标。例如。 kubectl get --raw /apis/custom.metrics.k8s.io/v1beta1 导致空指标:"kind":"APIResourceList","apiVersion":"v1","groupVersion":"custom.metrics.k8s.io/v1beta1","resources":[] 您的网址似乎是正确的。我没有部署prometheus-adapter,但我可以从 pod 内卷曲 URL(格式与您的格式相似)。你能试试这个吗?以排除集群 dns 的任何问题。 从 POD 中(在不同的命名空间中)我可以运行 wget -O - http://prometheus-kube-prometheus-prometheus.prom.svc.cluster.local:9090 并获得包含 &lt;title&gt;Prometheus Time Series Collection and Processing Server&lt;/title&gt;html 响应。 看起来差不多。您可以编辑您的问题并分享prometheus-adapter 的值文件吗?至于 HPA 的指标,首先要确认您已经部署了指标服务器吗? 此外,我尝试查询普罗米修斯 UI 使用的相同配置指标(如果这实际上是一个有效的 URL)。例如。执行wget -O - "http://prometheus-kube-prometheus-prometheus.prom.svc.cluster.local:9090/api/v1/query?query=%7Bnamespace%21%3D%22%22%2C__name__%21%7E%22%5Econtainer_.*%22%7D&amp;time=1616751935.431" 会产生相同的 404。 【参考方案1】:

问题与用于通过 Ingress 公开 prometheus 的附加路径有关。

我在入口配置中使用了额外的路径前缀 /monitoring/prometheus/

解决方案也是告诉 prometheus-adapter,prometheus 是可访问的,包括。这个路径前缀。 因此,以下内容使 prometheus-adapter 很高兴:

--prometheus-url=http://prometheus-kube-prometheus-prometheus.prom.svc.cluster.local:9090/monitoring/prometheus/

现在我可以在执行时看到自定义指标

kubectl get --raw /apis/custom.metrics.k8s.io/v1beta1

感谢“rock'n rolla”提供一些提示!

【讨论】:

那是我相信你所做的“轻微定制”部分 ;)【参考方案2】:

我同时使用了 helm 图表(kube-prometheus-stackprometheus-adapter)。

适用于我的附加路径前缀是“/”,但是,prometheus url 必须与堆栈的 helm-install 参数的名称(“helm install”)。我使用“prostack”作为堆栈名称。所以最后,它对我有用:

helm install <adapter-name> -n <namespace> --set prometheus.url=http://prostack-kube-prometheus-s-prometheus.monitoring.svc.cluster.local --set prometheus.port=9090 --set prometheus.path=/

【讨论】:

以上是关于prometheus-adapter 使用的正确 prometheus URL 是啥的主要内容,如果未能解决你的问题,请参考以下文章

安装Prometheus-adapter后top pod出错无输出

安装Prometheus-adapter后top pod出错无输出

prometheus-adapter 空项目列表但成功的 HTTP 请求

在 Kubernetes 中使用多个自定义指标适配器

使用 Prometheus 适配器的 Horizo​​ntal Pod Autoscaler (HPA) 自定义指标(单位是如何定义的?)

Kubernetes集群安装kube-prometheus后无法执行kubectl top node