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

Ray*_*n D 8 security kubernetes prometheus istio prometheus-operator

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

说明:

  1. 在集群中有一个主要的prometheus 操作员 v0.34 配置
  2. 我在集群B SLAVE prometheus 2.13.1 配置中

两者都通过 helm 成功安装,我可以通过访问 localhostport-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
Run Code Online (Sandbox Code Playgroud)

我把目标如下:

集群 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

在此处输入图片说明

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

  1. 为了能够state在绿色上看到该目标(见图片),我在集群中配置了 prometheus 服务器,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
Run Code Online (Sandbox Code Playgroud)

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

    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

Run Code Online (Sandbox Code Playgroud)

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

OhH*_*ark 2

  1. 您应该考虑使用附加抓取配置

AdditionalScrapeConfigs允许指定包含附加 Prometheus 抓取配置的 Secret 的密钥。指定的抓取配置将附加到 Prometheus Operator 生成的配置中。

  1. 恐怕这没有得到官方支持。但是,您可以更新prometheus.ymlHelm 图表中的部分。如果您想了解更多信息,请查看此博客

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

默认情况下,与 Prometheus 及其导出器的连接未加密和身份验证。这是使用 TLS 证书和 stunnel 解决此问题的一种方法

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

请告诉我这是否有帮助。