In my docker setup, I maintain targets.json
file which is dynamically updated with targets to probe. The file starts empty but is appended with targets during some use case.
sample targets.json
[
{
"targets": [
"x.x.x.x"
],
"labels": {
"app": "testApp1"
}
},
{
"targets": [
"x.x.x.x"
],
"labels": {
"app": "testApp2"
}
}
]
This file is then provided to prometheus configuration as file_sd_configs
. Everything works fine, targets get added to targets.json file due to some event in application and prometheus starts monitoring along with blackbox for health checks.
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
Inside my node.js application I am able to append data to targets.json file, but now I trying to replicate this in Kubernetes on minikube. I tried adding in ConfigMap as following and it works, but I dont want to populate targets in configuration, but rather maintain a json file.
Can this be done using Persistent Volumes? The pod running Prometheus will always read the targets file and pod running application will write to targets file.
kind: ConfigMap
apiVersion: v1
metadata:
name: prometheus-cm
data:
targets.json: |-
[
{
"targets": [
"x.x.x.x"
],
"labels": {
"app": "testApp1"
}
}
]
Simply, what strategy in Kubernetes is recommended to so that one pod can read a json file and another pod can write to that file.