Home > Software engineering >  Prometheus /etc/config/prometheus.yml: no such file or directory with Kubernetes
Prometheus /etc/config/prometheus.yml: no such file or directory with Kubernetes

Time:10-19

I tried to deploy prometheus with using https://prometheus-community.github.io/helm-charts But I wanted to have a custom prometheus.yml Therefore the approach I used is the build the prometheus docker image by copying the customised prometheus.yml file. (via a simple pipeline)

Dockerfile I use

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

It builds the image successfully and when I try to deploy this image via the helm, container fails with the following error.

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"

I am not sure if this is the ideal approach. What can I do to have a customised prometheus.yml inside the prometheus pod. (I can have the config within the values.yaml in helm but I prefer to have a separate file. So I can manage it easily)

CodePudding user response:

Building an image just to change configuration isn't a convenient way to configure an application. Consider, you will have to update the image (build, push, pull) each time you need to change configuration. Besides, this community Prometheus stack has an easy way to customize prometheus.yml via the values.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

You can add the desired changes under serverFiles."prometheus.yml" key and then simply redeploy the stack.

CodePudding user response:

The challenege was to manage the prometheus.yml as a seperate file. I have found extraConfigmapMounts option in the community Prometheus stack.

Therefore creating a configMap using the prometheus.yml and mount it to the application seems like a good way of achieving it. Simply use of the value server.extraConfigmapMounts to add the configuration.

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