<p>While running Prometheus in Kubernetes, I'm pushing out new config via a <code>ConfigMap</code>. ConfigMaps are exposed as files in the container.</p>

<p>I would love Prometheus to automatically reload its configuration when the file changes.</p>

<p>Would something like this work?</p>

<pre><code>inotifywait -q -m -e close_write /etc/prometheus/config.yml |
while read -r filename event; do
  curl -X POST http://localhost:9090/-/reload
done
</code></pre>

<p>(Edit: I took some time to get this fully to work)
this works with a small sidecar container. The configuration could look like this:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: prometheus
spec:
  replicas: 1
  template:
    ....
    spec:
      containers:
        ... (your actual container config goes here) ...
      - name: refresh
        imagePullPolicy: Always
        args:
        - /etc/prometheus/config.yml
        - http://localhost:9090/-/reload
        image: tolleiv/k8s-prometheus-reload
        volumeMounts:
          - name: config-volume
            mountPath: /etc/prometheus
      volumes:
        - name: config-volume
          configMap:
            name: prometheus
</code></pre>

<p>The actual check is done with this script where the observed file and the URL are passed as parameters:</p>

<pre><code>#!/bin/sh
while true; do
   inotifywait "$(readlink -f $1)"
   echo "[$(date +%s)] Trigger refresh"
   curl -sSL -X POST "$2" &gt; /dev/null
done
</code></pre>

<p>Everything can be found in <a href="https://hub.docker.com/r/tolleiv/k8s-prometheus-reload/" rel="nofollow noreferrer">this container on Dockerhub</a></p>

<p>Keeping a single <code>inotifywait</code> with the <code>-m</code> didn't work because of symlink juggling which is done by Kubernetes when the <code>ConfigMap</code> changes.</p>
