K8S - 使用 Prometheus 以安全的方式监控另一个 prometheus 实例

K8S - using Prometheus to monitor another prometheus instance in secure way

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

场景:

  1. have in cluster A MAIN prometheus operator v0.34 config
  2. I've in cluster B SLAVE prometheus 2.13.1 config

两者都通过 helm 安装成功,我可以通过 port-forwarding 访问本地主机并查看每个集群上的抓取结果。

我做了以下步骤

在运算符上使用(主集群 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

我的目标如下:

集群 B 中的普罗米修斯上(我想从中收集数据)我使用:

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

现在我的主要question/gaps。 (安全和验证)

  1. 为了能够在绿色上看到目标 state(见图),我在集群 B 中配置了普罗米修斯服务器,而不是使用 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或slave B的证书?

  1. 您应该考虑使用 Additional Scrape Configuration

AdditionalScrapeConfigs allows specifying a key of a Secret containing additional Prometheus scrape configurations. Scrape configurations specified are appended to the configurations generated by the Prometheus Operator.

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

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

Connections to Prometheus and its exporters are not encrypted and authenticated by default. This is one way of fixing that with TLS certificates and stunnel.

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

如果有帮助,请告诉我。

几个选项spring要考虑:

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