Reload Prometheus ConfigMap without Restarting the Kubernetes Pod

We run Prometheus on Kubernetes. Every time we make changes to Prometheus ConfigMap, we end up restarting the pod so that the new configuration would be picked up.

While Prometheus configuration does not change very often, we would prefer to have a way to do this without downtime.

The Solution

Use Prometheus web flags to enable HTTP reloads and add configmap-reload container to reload the ConfigMap. The configmap-reload is a simple binary to trigger a reload when Kubernetes ConfigMaps are updated.

Starting with Prometheus 2.0, the --web.enable-lifecycle flag controls HTTP reloads and shutdowns of Prometheus. This is disabled by default, therefore we need to enable it by adding the parameter to our Prometheus deployment definition. When enabled, the reload endpoint will be accessible under the /-/reload path.

We have to update our Kubernetes Deployment configuration and add a new container for prometheus-server-configmap-reload.

See example below. Note that most of the deployment configuration that is not relevant to this change has been omitted.

apiVersion: apps/v1
kind: Deployment
  name: prometheus-server
  namespace: monitoring
        - name: config-volume
            name: prometheus-server
            defaultMode: 420
        - name: prometheus-server-configmap-reload
          image: jimmidyson/configmap-reload:v0.5.0
          imagePullPolicy: IfNotPresent
            - '--volume-dir=/etc/config'
            - '--webhook-url='
            - name: config-volume
              readOnly: true
              mountPath: /etc/config
        - name: prometheus-server
          imagePullPolicy: IfNotPresent
            - '--config.file=/etc/config/prometheus.yml'
            - '--enable-feature=expand-external-labels'
            - '--storage.tsdb.path=/data'
            - '--storage.tsdb.retention.time=14d'
            - '--web.enable-lifecycle'

Deploy the changes to Kubernetes. After that, the prometheus-server-configmap-reload container should reload all changes to the ConfigMap automatically without a need of restarting the Prometheus pod.


2 thoughts on “Reload Prometheus ConfigMap without Restarting the Kubernetes Pod

Leave a Reply

Your email address will not be published. Required fields are marked *