在集群外暴露普罗米修斯数据

Expose prometheus data outside the cluster

我们有使用 Go 库将状态写入 prometheus 的组件, 我们能够在 Prometheus UI 中看到数据, 我们有组件在 K8S 集群 之外,需要从中提取数据 Prometheus,我该如何公开这些指标?有什么我应该使用的组件吗?

您可能需要查看 Prometheus 文档的 Federation 部分。

Federation allows a Prometheus server to scrape selected time series from another Prometheus server. Commonly, it is used to either achieve scalable Prometheus monitoring setups or to pull related metrics from one service's Prometheus into another.

需要使用 Ingress 或 nodePort 将 Prometheus 服务暴露在集群之外,并配置 Center Prometheus 以从暴露的服务端点抓取指标。您还将设置一些适当的身份验证。这是其中的一个 example

我想到的第二种方法是使用 Kube-state-metrics

kube-state-metrics is a simple service that listens to the Kubernetes API server and generates metrics about the state of the objects.

指标在 HTTP 端点上导出,旨在供 Prometheus 本身或与 Prometheus 客户端端点兼容的抓取工具使用。然而,这与 Metrics Server 不同,它生成关于 Kubernetes 对象状态的指标:节点状态、节点容量、所需副本数、pod 状态等。