<p>In my docker setup, I maintain <code>targets.json</code> file which is dynamically updated with targets to probe. The file starts empty but is appended with targets during some use case.</p>
<p><strong>sample targets.json</strong></p>
<pre><code>[
  {
    &quot;targets&quot;: [
      &quot;x.x.x.x&quot;
    ],
    &quot;labels&quot;: {
      &quot;app&quot;: &quot;testApp1&quot;
    }
  },
  {
    &quot;targets&quot;: [
      &quot;x.x.x.x&quot;
    ],
    &quot;labels&quot;: {
      &quot;app&quot;: &quot;testApp2&quot;
    }
  }
]
</code></pre>
<p>This file is then provided to prometheus configuration as <code>file_sd_configs</code>. 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.</p>
<pre><code>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
</code></pre>
<p>Inside my node.js application I am able to append data to targets.json file, <strong>but</strong> 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.</p>
<p>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.</p>
<pre><code>kind: ConfigMap
apiVersion: v1
metadata:
  name: prometheus-cm
data:
  targets.json: |-
    [
      {
        &quot;targets&quot;: [
          &quot;x.x.x.x&quot;
        ],
        &quot;labels&quot;: {
          &quot;app&quot;: &quot;testApp1&quot;
        }
      }
    ]
</code></pre>
<p>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.</p>

maopuppets
<p>In order to achieve your goal you need to use <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/" rel="nofollow noreferrer">PVC</a>:</p>
<blockquote>
<p>A <strong>PersistentVolume (PV)</strong> is a piece of storage in the cluster that has
been provisioned by an administrator. It is a resource in the cluster
just like a node is a cluster resource. PVs are volume plugins like
Volumes, but have a lifecycle independent of any individual pod that
uses the PV. This API object captures the details of the
implementation of the storage, be that NFS, iSCSI, or a
cloud-provider-specific storage system.</p>
<p>A <strong>PersistentVolumeClaim (PVC)</strong> is a request for storage by a user. It
is similar to a pod. Pods consume node resources and PVCs consume PV
resources. Pods can request specific levels of resources (CPU and
Memory). Claims can request specific size and access modes (e.g., can
be mounted once read/write or many times read-only).</p>
</blockquote>
<p>The json file needs to be persisted if one pod has to write to it and another one to read it. There is an <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/" rel="nofollow noreferrer">official guide</a> describing that concept in steps:</p>
<ul>
<li><p>Create a <code>PersistentVolume</code></p>
</li>
<li><p>Create a <code>PersistentVolumeClaim</code></p>
</li>
<li><p>Create a <code>Pod</code> that uses your <code>PersistentVolumeClaim</code> as a volume</p>
</li>
</ul>
<p>I also recommend reading this: <a href="https://medium.com/asl19-developers/create-readwritemany-persistentvolumeclaims-on-your-kubernetes-cluster-3a8db51f98e3" rel="nofollow noreferrer">Create ReadWriteMany PersistentVolumeClaims on your Kubernetes Cluster</a> as a supplement.</p>
