【问题标题】:How to scrape metrics-server to prometheus outside kubernetes cluster如何在 kubernetes 集群外将 metrics-server 抓取到 prometheus
【发布时间】:2021-04-13 16:55:00
【问题描述】:

我已经安装了 kubernetes metrics-server https://github.com/kubernetes-sigs/metrics-server 它工作正常,我可以使用“kubectl top pods”和“kubectl top nodes”,现在我想将指标刮到 kubernetes 集群外的 prometheus 以显示在 Grafana 上,我试过的是

  1. 使用 NodePort 公开 metrics-server 服务但无法正常工作,出现一些 https 问题
  2. 从https://github.com/ghouscht/metrics-server-exporter/安装metrics-server-exporter(这个只刮了几个指标,我在grafana上看不到)和https://github.com/grupozap/metrics-server-exporter/(这个不是http应用程序,所以我不能暴露为NodePort服务)

我该怎么办?

【问题讨论】:

  • 在数据源设置过程中,您是否在 Grafana 中应用了With CA Cert?
  • 我只是对 prometheus 和 grafana 都使用 http

标签: kubernetes prometheus metrics-server


【解决方案1】:

试试这些并告诉我。

1.首先你应该运行 kube-state-metrics 来收集所有 kubernetes 指标。

2.在 kube-state-metrics 上使用 pod 注释,公开指标,如

prometheus.io/scrape: 'true'
prometheus.io/port: 'port'
prometheus.io/path: '/metrics'
prometheus.io/scheme: 'http'

这应该从 pod 级别公开您的指标。要检查这一点,您可以执行到 pod 并在端口上执行 curl 请求,然后是路径

3.现在运行一个 prometheus 代理,它可以从该端口抓取指标并将其发送到后端数据库服务器

4.在你的 grafana 代理中配置 prometheus ds 应该完成

【讨论】:

  • 感谢您的信息,kube-state-metrics 工作正常,但我应该从普罗米修斯刮掉所有 nodePort ip 吗?还是 1 个 nodePort 就足够了?我应该像你说的那样把 pod 注释放在哪里?是否符合部署规范?在我的 Grafana 上显示了 pod 列表,但没有关于 CPU、内存、带宽使用情况 prnt.sc/witosr 的数据,我正在使用此模板 grafana.com/grafana/dashboards/12120
  • 它现在可以工作了,我不知道 grafana 仪表板模板上的一些指标不同,所以我需要自己编辑例如:kube_pod_container_resource_requests_memory_bytes{pod="$pod", container=~"$container "} 我编辑到 kube_pod_container_resource_requests{pod="$pod", resource="memory", container=~"$container"}
  • 我不明白这是如何被接受的答案,当最初的问题是在 Kubernetes 集群之外的 Prometheus 实例时?新问题是stackoverflow.com/questions/70457308/…
【解决方案2】:

你可以使用helm来安装kube-prometheus-stack。

它将安装 Node Exporter、kube-state-metrics 和 prometheus operator 以及其他依赖项,以便您监控集群。

您可以使用以下方式安装它:

helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo add stable https://charts.helm.sh/stable
helm repo update
helm install [RELEASE_NAME] prometheus-community/kube-prometheus-stack

安装后,您可以访问您的 grafana URL 并配置仪表板。

您可以在 grafana 中添加 prometheus 作为数据源 [Configuration -> Data Source](prometheus URL 应默认设置)并导入 kubernetes dashboard 以显示有关在 Kubernetes 节点上运行的容器的摘要指标。

【讨论】:

  • 感谢您的建议,但要知道我仍在学习,我更喜欢手动安装,所以我可以了解我的 k8s 集群中发生了什么
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-26
  • 2021-09-10
  • 2021-09-12
  • 1970-01-01
相关资源
最近更新 更多