Last active
August 13, 2020 15:24
-
-
Save scott2449/ec0b81edbfe41170830df6a3beb2b2f3 to your computer and use it in GitHub Desktop.
prom-reload.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
VOLUME_DIRECTORY="/etc/prometheus/rules/changeme" | |
for arg in "$@" | |
do | |
case $arg in | |
-VD=*|--volume-dir=*) | |
VOLUME_DIRECTORY="${arg#*=}" | |
shift | |
;; | |
esac | |
done | |
inotifywait -e delete -m -r $VOLUME_DIRECTORY | | |
while read path action file; do | |
# second delete check is to ignore events that look like DELETE,ISDIR .. we want file deletes only | |
if [[ $action = "DELETE" ]]; then | |
pkill -HUP prometheus | |
echo "$(date) - Reloaded prometheus because the $action event occurred on file: [$path $file] " | |
fi | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
labels: | |
app: prometheus | |
name: prometheus | |
spec: | |
replicas: 1 | |
selector: | |
matchLabels: | |
app: prometheus | |
template: | |
metadata: | |
labels: | |
app: prometheus | |
spec: | |
shareProcessNamespace: true | |
containers: | |
- name: reloader | |
args: | |
- --volume-dir=/etc/alerts/ | |
volumeMounts: | |
- name: alert-volume | |
mountPath: /etc/alerts | |
image: docker.io/scott2449/prom-reload:v14 | |
- name: prometheus | |
args: | |
- --storage.tsdb.retention=6h | |
- --config.file=/etc/prometheus/prometheus.yml | |
- --storage.tsdb.path=/data/ | |
# commenting this out to stop the api (also allows for reload from thanos) | |
#- --web.enable-lifecycle | |
- --storage.tsdb.no-lockfile | |
- --storage.tsdb.min-block-duration=2h | |
- --storage.tsdb.max-block-duration=2h | |
- --query.max-concurrency=10 | |
image: docker.io/prom/prometheus:v2.15.1 | |
livenessProbe: | |
httpGet: | |
path: /-/healthy | |
port: 9090 | |
ports: | |
- containerPort: 9090 | |
name: http | |
readinessProbe: | |
httpGet: | |
path: /-/ready | |
port: 9090 | |
volumeMounts: | |
- mountPath: /data/ | |
name: config-shared | |
- name: alert-volume | |
mountPath: /etc/alerts | |
- mountPath: /etc/prometheus | |
name: config-volume | |
volumes: | |
- name: config-shared | |
emptyDir: {} | |
- name: alert-volume | |
configMap: | |
name: alerts | |
- configMap: | |
name: prometheus | |
name: config-volume |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Because of how symlinks and config map updates work, delete is the best event to use here that doesn't cause loops or missed events with the absolute smallest amount of code. I tried like 30 different versions of events and inotifywait flags analyzing what precisely k8s is doing when reloading the config map.