【问题标题】:K8S - using Prometheus to monitor another prometheus instance in secure wayK8S - 使用 Prometheus 以安全的方式监控另一个 prometheus 实例
【发布时间】:2019-11-21 16:54:12
【问题描述】:

我已经在集群 A(主舞会)上安装了 Prometheus operator 0.34(按预期工作) 现在我想使用federation 选项,我的意思是从位于其他 K8S 集群的其他 Prometheus 收集指标 B

Secnario:

  1. 在集群 A 主prometheus operator v0.34 config
  2. 我在集群 B SLAVE prometheus 2.13.1 config

都通过 helm 安装成功,我可以通过 port-forwarding 访问 localhost 并查看每个集群的抓取结果。

我做了以下步骤

在算子上使用(主集群 A)additionalScrapeconfig 我已将以下内容添加到 values.yaml 文件并通过 helm 进行更新。

additionalScrapeConfigs:
 - job_name: 'federate'  
   honor_labels: true
   metrics_path: /federate
   params:
     match[]:
       - '{job="prometheus"}'
       - '{__name__=~"job:.*"}'
   static_configs:
     - targets:
       - 101.62.201.122:9090 # The External-IP and port from the target prometheus on Cluster B

我的目标如下:

在 cluster B 内的 prometheus 上(我想从中收集数据)我使用:

kubectl get svc -n monitoring

并获得以下条目:

获取EXTERNAL-IP 并将其放入additionalScrapeConfigs 配置条目中。

现在我切换到集群 A 并运行 kubectl port-forward svc/mon-prometheus-operator-prometheus 9090:9090 -n monitoring

使用localhost:9090 打开浏览器查看图表并点击Status 然后点击Targets

并通过工作federate查看新目标

现在我的主要问题/差距。 (安全和验证)

  1. 为了能够看到绿色的目标state(参见图片),我在集群B 中配置prometheus 服务器,而不是使用type:NodePort 来使用type:LoadBalacer,这会在外部公开指标,这可以是适合测试,但我需要保护它,怎么做? 如何使 e2e 以安全方式...

tls https://prometheus.io/docs/prometheus/1.8/configuration/configuration/#tls_config

在集群A(主集群)中,我们使用istio 的输出服务证书,如下所示

tls:
   mode: SIMPLE
   privateKey: /etc/istio/oss-tls/tls.key
   serverCertificate: /etc/istio/oss-tls/tls.crt

我看到文档里面有一个配置选项

    additionalScrapeConfigs:
     - job_name: 'federate'  
       honor_labels: true
       metrics_path: /federate
       params:
         match[]:
           - '{job="prometheus"}'
           - '{__name__=~"job:.*"}'
       static_configs:
         - targets:
           - 101.62.201.122:9090 # The External-IP and port from the target
#        tls_config:
#          ca_file: /opt/certificate-authority-data.pem
#          cert_file: /opt/client-certificate-data.pem
#          key_file: /sfp4/client-key-data.pem
#          insecure_skip_verify: true

但不确定我需要在 prometheus operator config 中使用哪个证书,主 prometheus A 或从 B 的证书?

【问题讨论】:

标签: security kubernetes prometheus istio prometheus-operator


【解决方案1】:
  1. 您应该考虑使用Additional Scrape Configuration

AdditionalScrapeConfigs 允许指定 Secret 的密钥 包含额外的 Prometheus 抓取配置。刮 指定的配置附加到生成的配置中 由 Prometheus 操作员提供。

  1. 我担心这不受官方支持。但是,您可以更新 Helm 图表中的 prometheus.yml 部分。如果您想了解更多信息,请查看this blog

  2. 我在这里看到两个选项:

与 Prometheus 及其导出器的连接未加密,并且 默认通过身份验证。 This is one way of fixing that with TLS certificates and stunnel.

或者指定Secrets,您可以将其添加到您的抓取配置中。

如果有帮助,请告诉我。

【讨论】:

  • 非常感谢您的回答 1+!不幸的是,我仍在努力使其工作,我已经提供了赏金,如果您能提供执行此操作的步骤,那就太好了......非常感谢!
【解决方案2】:

我想到了几个选项:

  1. 将两个集群放在同一个网络空间,并在它们前面放一个防火墙
  2. 集群之间的 VPN 隧道。
  3. 使用 istio 多集群路由(但这可能会变得复杂):https://istio.io/docs/setup/install/multicluster

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-18
    • 1970-01-01
    • 2022-11-04
    • 2018-05-11
    • 1970-01-01
    • 2018-05-22
    • 2016-05-29
    • 2020-08-09
    相关资源
    最近更新 更多