在我的 docker 设置中,我维护targets.json
的文件是动态更新的,其中包含要探测的目标。该文件开始为空,但在某些用例中附加了目标。
示例目标.json
[
{
"targets": [
"x.x.x.x"
],
"labels": {
"app": "testApp1"
}
},
{
"targets": [
"x.x.x.x"
],
"labels": {
"app": "testApp2"
}
}
]
然后将此文件提供给 prometheus 配置为file_sd_configs
. 一切正常,由于应用程序中的某些事件,目标被添加到 targets.json 文件中,prometheus 开始监控以及黑盒以进行健康检查。
scrape_configs:
- job_name: 'test-run'
metrics_path: /probe
params:
module: [icmp]
file_sd_configs:
- files:
- targets.json
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: blackbox:9115
在我的 node.js 应用程序中,我可以将数据附加到 targets.json 文件,但现在我试图在 minikube 上的 Kubernetes 中复制它。我尝试按以下方式添加 ConfigMap 并且它可以工作,但我不想在配置中填充目标,而是维护一个 json 文件。
这可以使用持久卷来完成吗?运行 Prometheus 的 pod 将始终读取目标文件,而运行应用程序的 pod 将写入目标文件。
kind: ConfigMap
apiVersion: v1
metadata:
name: prometheus-cm
data:
targets.json: |-
[
{
"targets": [
"x.x.x.x"
],
"labels": {
"app": "testApp1"
}
}
]
简单来说,在 Kubernetes 中推荐使用什么策略,以便一个 pod 可以读取 json 文件,而另一个 pod 可以写入该文件。