【问题标题】:Prometheus with multi-container pod on kubernetesPrometheus 与 kubernetes 上的多容器 pod
【发布时间】:2017-03-30 14:43:44
【问题描述】:

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

  • java
  • redis
  • nginx

对于每个容器,都有一个带有 Prometheus 导出器的容器。

问题是,如果 annotations 部分仅支持每个 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'

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

【问题讨论】:

    标签: docker kubernetes monitoring prometheus


    【解决方案1】:

    这是 Prometheus 的 example 工作。将其放入您自己的配置中。

    接下来,添加:

    annotations:
       prometheus.io/scrape: 'true'
    

    到您的 pod 元数据。

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

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

    【讨论】:

    • 要明确:在部署 yaml 添加 containerPort: "metrics" 并在代码本身中将 prometheus 服务器设置为在“metrics”端口上启动?并且 Dockerfile 还需要有EXPOSE metrics
    • 通过您的应用程序 dockerfile 使用 prometheus 指标公开您的端口,将 - name: metrics containerPort: 1234 添加到部署中的容器,将 annotations: prometheus.io/scrape: 'true' 添加到此 pod 元数据。就是这样。您无需将 prometheus 服务器设置为在“metrics”端口上启动
    • 道歉。我的意思是内部普罗米修斯指标报告。 (您在代码中开始将指标报告回主服务器)。感谢您的澄清
    • 一个示例 yaml 真的很有帮助。
    【解决方案2】:

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

    【讨论】:

    • 谢谢你的建议,伙计。似乎如果我只设置annotations: prometheus.io/scrape: 'true',Prometheus 会刮掉所有暴露的端口。所以,这对我来说已经足够了。
    猜你喜欢
    • 2022-10-26
    • 2017-08-25
    • 2020-02-21
    • 1970-01-01
    • 1970-01-01
    • 2021-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多