何为prometheus配置自动更新:
- prometheus CRD对象变更,导致prometheus的配置文件变更,需要reload prometheus让配置生效;
- prometheusrule CRD对象变更,导致prometheus的规则文件变更,需要reload prometheus让配置生效;
- serviceMonitor/podMonitor等CRD对象变更,导致prometheus的配置文件变更,需要reload prometheus让配置生效;
prometheus的POD中有3个container,其中包含:
- prometheus: prometheus-server,主容器;
- config-reloader: sidecar,负责reload prometheus的配置文件;
- rules-reloader: sidecar,负责reload prometheus的规则文件;
operator+prometheus+2个sidecar一起合作,完成了配置的自动更新。
1. sidecar的镜像及启动参数
2个sidecar的镜像版本,在operator的启动参数中指定:
containers:
- args:
- --kubelet-service=kube-system/kubelet
- --logtostderr=true
- --config-reloader-image=178.104.162.39:443/kubernetes/amd64/configmap-reload:v0.0.1
- --config-reloader-memory=50Mi
- --prometheus-config-reloader=178.104.162.39:443/kubernetes/amd64/prometheus-config-reloader:v0.40.0
image: 178.104.162.39:443/kubernetes/amd64/prometheus-operator:v0.40.0
imagePullPolicy: IfNotPresent
name: prometheus-operator
可以看到,rules-reloader的镜像版本v0.0.1,config-reloader的版本v0.40.0,由于config-reloader的代码跟operator的代码放在一起的,所以其版本也跟着operator的走。
2个sidecar的源码位置:
- config-reloader: 与operator源码在一起,https://github.com/prometheus...
- rules-reloader: https://github.com/jimmidyson...
prometheus及sidecar的启动参数:
prometheus:
Image: 178.104.162.39:443/kubernetes/amd64/prometheus:v2.20.0
Args:
--web.console.templates=/etc/prometheus/consoles
--web.console.libraries=/etc/prometheus/console_libraries
--config.file=/etc/prometheus/config_out/prometheus.env.yaml
--storage.tsdb.path=/prometheus
--storage.tsdb.retention.time=24h
--web.enable-lifecycle
--storage.tsdb.no-lockfile
--web.route-prefix=/
prometheus-config-reloader:
Image: 178.104.162.39:443/kubernetes/amd64/prometheus-config-reloader:v0.40.0
Args:
--log-format=logfmt
--reload-url=http://localhost:9090/-/reload
--config-file=/etc/prometheus/config/prometheus.yaml.gz
--config-envsubst-file=/etc/prometheus/config_out/prometheus.env.yaml
rules-configmap-reloader:
Image: 178.104.162.39:443/kubernetes/amd64/configmap-reload:v0.0.1
Args:
--webhook-url=http://localhost:9090/-/reload
--volume-dir=/etc/prometheus/rules/prometheus-k8s-rulefiles-0
2. sidecar与volume的挂载关系
4个volume分别被3个container挂载:
- prometheus-k8s-db: 存放prometheus data的目录,仅被prometheus挂载;
- prometheus-k8s: 存放prometheus配置压缩文件prometheus.yaml.gz,仅被config-reloader挂载;
- config-out: 存放prometheus配置文件,被prometheus和config-reloader挂载;
- prometheus-k8s-rulefiles-0: 存放prometheus的规则文件,被prometheus和rules-reloader挂载;
3. 结论先行
结论不难理解,但是里面的细节太多,对细节感兴趣的话可以阅读后面的详解文章。
- operator监听到prometheus配置变更,会更新secret(文件prometheus-yaml.gz,使用gz保证<1M),config-reloader监控到prometheus-yaml.gz文件有变更,将其解压至prometheus-env.yaml,然后发送reload给prometehus;
- operator监听到prometheusrule配置变更,会更新configmap(目录prometheus-k8s-rulefiles-0),rules-reloader监控到prometheus-k8s-rulefiles-0目录有变更,发送reload给prometheus;
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。