自动将新节点导出器添加到prometheus.yml的目标数组中

我有一个基本的prometheus.yml文件在我的环境,即..

### apiVersion: v1 kind: ConfigMap metadata: creationTimestamp: null name: prometheus-core data: prometheus.yml: | global: scrape_interval: 10s scrape_timeout: 10s evaluation_interval: 10s rule_files: - '/etc/prometheus-rules/*.rules' scrape_configs: # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. - job_name: 'prometheus' # Override the global default and scrape targets from this job every 5 seconds. scrape_interval: 5s # metrics_path defaults to '/metrics' # scheme defaults to 'http'. static_configs: - targets: ['localhost:9090'] 

现在,如果我添加新的节点到我的环境中,我的prometheus.yml文件应该自动更新并添加节点到下面的目标

 ### apiVersion: v1 kind: ConfigMap metadata: creationTimestamp: null name: prometheus-core data: prometheus.yml: | global: scrape_interval: 10s scrape_timeout: 10s evaluation_interval: 10s rule_files: - '/etc/prometheus-rules/*.rules' scrape_configs: # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. - job_name: 'prometheus' # Override the global default and scrape targets from this job every 5 seconds. scrape_interval: 5s # metrics_path defaults to '/metrics' # scheme defaults to 'http'. static_configs: - targets: ['localhost:9090','12.10.17.6:9100','12.10.17.19:9100'] 

任何人都可以build议我怎么做到这一点?

Prometheus支持Kubernetes服务发现机制,请参阅文档以获取详细信息。

所以,而不是static_configs部分,你应该添加一个类似于这样的部分:

 scrape_configs: - job_name: 'kubernetes-service-endpoints' kubernetes_sd_configs: - role: endpoints ... 

看到这个例子的configuration文件是如何完成的。