【问题标题】:Prometheus file based service discoveryPrometheus 基于文件的服务发现
【发布时间】:2023-03-22 22:10:01
【问题描述】:

我尝试了基于文件的服务发现,但每次更改配置映射(包含静态目标)时,我都会手动删除 prometheus pod 以获取配置更改。 prometheus 有什么方法可以在不删除 prometheus pod 的情况下自动获取配置更改?对这个问题有任何帮助吗?

我正在使用 helm chart 安装 prometheus-operator target.json 文件

[
  {
    "labels": {
      "app": "web",
      "env": "dev"
    },
    "targets": [
      "web.dev.svc.cluster.local"
   ]
  }
]```

command I used to create configmap

kubectl create cm static-config --from-file=target.json -n monitoring

prometheus-operator.yaml

```volumes:
- name: config-volume
  configMap:
    name: static-config

volumeMounts:
- name: config-volume
  mountPath: /etc/prometheus/config


additionalScrapeConfigs:
- job_name: 'file-based-targets'
  file_sd_configs:
  - files:
    - '/etc/prometheus/config/target.json'```

【问题讨论】:

    标签: kubernetes prometheus service-discovery prometheus-operator


    【解决方案1】:

    Prometheus 根据文档使用文件监视自动重新加载 file_sd_configs:

    它读取一组包含零个或多个 列表的文件。通过磁盘监视检测所有定义文件的更改并立即应用。文件可能以 YAML 或 JSON 格式提供。仅应用导致结构良好的目标组的更改。

    https://prometheus.io/docs/prometheus/latest/configuration/configuration/#file_sd_config

    如果您需要添加更多目标文件,您可以为文件使用通配符,例如:

    scrape_configs:
    - job_name: 'file-based-targets'
      file_sd_configs:
      - files:
        - '/etc/prometheus/targets/*.json'
    

    如果您仍需要从 configmap 重新加载,您可以将另一个容器添加到 Prometheus CRD 并使用内置的 prometheus-operator/prometheus-config-reloader(这是重新加载 Prometheus 配置和规则的方式)或以下之一:

    【讨论】:

      猜你喜欢
      • 2018-07-07
      • 2018-09-29
      • 1970-01-01
      • 2017-07-03
      • 2021-10-11
      • 1970-01-01
      • 1970-01-01
      • 2021-04-17
      • 1970-01-01
      相关资源
      最近更新 更多