在 kubernetes 上使用多容器 pod 的普罗米修斯

Prometheus with multi-container pod on kubernetes

我的 kubernetes 部署中有一个多容器 pod:

对于这些容器中的每一个,还有一个带有 Prometheus 导出器的容器。

问题是,如果注释部分仅支持每个 pod 一个端口,我如何将这些端口公开给 Prometheus?

annotations:
  prometheus.io/scrape: 'true'
  prometheus.io/port: 'xxxx'

但我需要这样的东西:

annotations:
  prometheus.io/scrape: 'true'
  prometheus.io/port_1: 'xxxx'
  prometheus.io/port_2: 'yyyy'
  prometheus.io/port_3: 'zzzz'

也许还有其他方法可以从我的多容器中抓取所有指标 pods?在此先感谢您提供任何帮助。

您建议的注释应该有效。为每个端口注释创建一个 scrape_config,仅保留与相应注释端口名称匹配的目标。

这是普罗米修斯的 example 工作。放在自己的配置里。

接下来,添加:

annotations:
   prometheus.io/scrape: 'true'

到您的广告连播元数据。

并且在每个为 prom 提供 /metrics 的容器上,创建一个适当的端口,命名为 metrics

就是这样。 Prometheus 只会抓取那些端口,不会有任何情况,比如当您的 redis 实例在其 6379 端口上收到 http 请求时。