2017-02-02 3 views
1

Kubernetes에서 Prometheus를 실행하는 동안 ConfigMap을 통해 새 구성을 푸시합니다. ConfigMaps는 컨테이너에 파일로 표시됩니다.기본 컨테이너를 실행하면 기본 ConfigMap이 변경 될 때 Prometheus가 해당 구성을 다시로드하도록 트리거하는 방법은 무엇입니까?

파일이 바뀔 때 Prometheus가 자동으로 구성을 다시로드하는 것을 좋아합니다.

이 작품이 마음에 드시나요?

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

나는 내 대답을 업데이트했습니다. 실제로 모든 사람들이 사용할 수있는 완전히 작동하는 솔루션을 가지고 있다는 사실을 발견했습니다. 그게 너에게 효과가 있다면 듣기 좋을거야 – pagid

답변

2

(편집 : 나는 일에 완전히이를 얻기 위해 약간의 시간이 걸렸다)이 작은 사이드카 컨테이너와 함께 작동 을. 구성은 다음과 같을 수 있습니다 :

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 

실제 검사가 관찰 된 파일과 URL 매개 변수로 전달되는이 스크립트로 수행됩니다

모든 것이 this container on Dockerhub

에서 찾을 수 있습니다
#!/bin/sh 
while true; do 
    inotifywait "$(readlink -f $1)" 
    echo "[$(date +%s)] Trigger refresh" 
    curl -sSL -X POST "$2" > /dev/null 
done 

ConfigMap이 변경되면 Kubernetes가 수행하는 심볼릭 링크 저글링 때문에 을 -m으로 유지하는 것이 작동하지 않습니다.

+0

와우 그게 아주 완전한 답이다! 불행히도 나는 그것이 prometheus 로그를 통해 초당 약 100 개의 재 장전을 유발하는 것을보고있다. – checketts

+0

어쩌면 그것이 파일을 만들기 전에 파일에 md5 비교 않았다면 ... – checketts

+0

나는 이것을 시도 할 것이다 : http://unix.stackexchange.com/a/166608 – checketts

0

또 다른 옵션은 livenessProbe 명령을 사용하고 구성이 변경되었을 때 Pod의 다시 시작을 트리거하는 것입니다.

apiVersion: extensions/v1beta1 
kind: Deployment 
metadata: 
    name: prometheus 
spec: 
    replicas: 1 
    template: 
    metadata: 
     labels: 
     app: prometheus 
    spec: 
     containers: 
     - name: prometheus 
     image: prom/prometheus:latest 
     ports: 
     - containerPort: 9090 
     volumeMounts: 
      - name: config-volume 
      mountPath: /etc/prometheus 
     livenessProbe: 
      exec: 
      command: 
      - /bin/sh 
      - -c 
      - "test -z $(find /etc/prometheus -mmin -2)" 
      initialDelaySeconds: 300 
      periodSeconds: 10 
     volumes: 
     - name: config-volume 
      configMap: 
      name: prometheus 

단점이 방법은 메모리에 캐시 된 데이터를 잃어 버릴 거라고 할 수 있지만 똑바로 앞으로이고 사이드카 용기를 필요로하지 않습니다 다음과 같을 수

.