Prometheus /etc/config/prometheus.yml: Kubernetes 没有这样的文件或目录

Prometheus /etc/config/prometheus.yml: no such file or directory with Kubernetes

我尝试使用 https://prometheus-community.github.io/helm-charts 部署 prometheus 但是我想要一个自定义的 prometheus.yml 因此我使用的方法是通过复制自定义的 prometheus.yml 文件来构建 prometheus docker 图像。 (通过一个简单的管道)

我用的Dockerfile

FROM quay.io/prometheus/prometheus:v2.26.0
ADD config /etc/config/

它成功构建了镜像,当我尝试通过 helm 部署这个镜像时, 容器失败并出现以下错误。

level=error ts=2021-10-14T15:26:02.525Z caller=main.go:347 msg="Error loading config (--config.file=/etc/config/prometheus.yml)" err="open /etc/config/prometheus.yml: no such file or directory"

我不确定这是否是理想的方法。 我该怎么做才能在 prometheus pod 中自定义 prometheus.yml。 (我可以在 helm 的 values.yaml 中进行配置,但我更喜欢有一个单独的文件。这样我可以轻松管理它)

构建映像只是为了更改配置并不是配置应用程序的便捷方式。考虑一下,每次需要更改配置时都必须更新映像(构建、推送、拉取)。此外,这个社区 Prometheus 堆栈有一种通过 values.yml:

自定义 prometheus.yml 的简单方法
serverFiles:
  prometheus.yml:
    rule_files:
      - /etc/config/recording_rules.yml
      - /etc/config/alerting_rules.yml
      - /etc/config/rules
      - /etc/config/alerts
    scrape_configs:
      - job_name: prometheus
        static_configs:
          - targets:
            - localhost:9090

您可以在 serverFiles."prometheus.yml" 键下添加所需的更改,然后只需重新部署堆栈即可。

挑战是将 prometheus.yml 作为一个单独的文件进行管理。我在社区 Prometheus 堆栈中找到了 extraConfigmapMounts 选项。

因此使用 prometheus.yml 创建一个 configMap 并将其安装到应用程序似乎是实现它的好方法。 只需使用值 server.extraConfigmapMounts 添加配置。

extraConfigmapMounts:
    - name: prometheus-configmap
      mountPath: /prometheus/config/
      subPath: ""
      configMap: <configMap name>
      readOnly: true