(Edit: I took some time to get this fully to work)
this works with a small sidecar container. The configuration could look like this:
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
The actual check is done with this script where the observed file and the URL are passed as parameters:
#!/bin/sh
while true; do
inotifywait "$(readlink -f $1)"
echo "[$(date +%s)] Trigger refresh"
curl -sSL -X POST "$2" > /dev/null
done
Everything can be found in this container on Dockerhub
Keeping a single inotifywait
with the -m
didn't work because of symlink juggling which is done by Kubernetes when the ConfigMap
changes.