配置prometheus访问应用部署的另一个集群

Configuring prometheus to access another cluster that applications deployed

我是在 k8s 中使用 Prometheus 等监控工具的新手。我们有两个独立的集群,一个用于我们部署的应用程序,一个用于我们只想部署监控、日志记录工具。

但是我有点困惑如何处理这个?

1.How 服务于 prometheus 的集群可以连接到应用程序集群并能够拉取指标?

2.How如果我想设置网络策略,我应该指定命名空间吗?

3.What 除了导出指标外,我应该在应用程序端为 helm chart 做些什么?

# Allow traffic from pods with label app=prometheus in namespace with label name=monitoring
# to any pod in <YOUR_APPLICATION_NAMESPACE>
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: monitoring.prometheus.all
  namespace: <YOUR_APPLICATION_NAMESPACE>
spec:
  ingress:
  - from:
    - namespaceSelector:
        matchLabels:
          name: monitoring
      podSelector:
        matchLabels:
          app: prometheus
  podSelector: {}
  policyTypes:
  - Ingress

这不就是你想要的吗?

1) Prometheus federation

Prometheus federation is a Prometheus server that can scrape data from other Prometheus servers. It supports hierarchical federation, which in our case resembles a tree.

我们每个集群都安装了默认版本的Prometheus服务器,并且在中央监控集群中部署了Prometheus联邦服务器和Grafana。 Prometheus 联合会从我们集群中 运行 的所有其他 Prometheus 服务器中抓取数据。为了将来的扩展,中央 Prometheus 联邦可用于从多个 Prometheus 联邦服务器中抓取数据,这些服务器从数十个集群的组中抓取数据。

更多信息在这里:https://developers.mattermost.com/blog/cloud-monitoring/

2) Prometheus configuration to scrape Kubernetes outside the cluster yaml 示例

3) Linkedin Monitoring Kubernetes with Prometheus - outside the cluster! article and Reddit Monitoring K8s by Prometheus Outside Cluster 相关讨论