<p>I have a basic prometheus.yml file in my environment i.e ..</p>

<pre><code>###
apiVersion: v1
kind: ConfigMap
metadata:
  creationTimestamp: null
  name: prometheus-core
data:
  prometheus.yml: |
    global:
      scrape_interval: 10s
      scrape_timeout: 10s
      evaluation_interval: 10s

    rule_files:
      - '/etc/prometheus-rules/*.rules'

    scrape_configs:
       # The job name is added as a label `job=&lt;job_name&gt;` to any timeseries scraped from this config.
      - job_name: 'prometheus'

        # Override the global default and scrape targets from this job every 5 seconds.
        scrape_interval: 5s

        # metrics_path defaults to '/metrics'
        # scheme defaults to 'http'.

        static_configs:
          - targets: ['localhost:9090'] 
</code></pre>

<p>Now if I add new nodes to my environment, my prometheus.yml file should automatically get updated and add the nodes to the targets below i.e.</p>

<pre><code>###
apiVersion: v1
kind: ConfigMap
metadata:
  creationTimestamp: null
  name: prometheus-core
data:
  prometheus.yml: |
    global:
      scrape_interval: 10s
      scrape_timeout: 10s
      evaluation_interval: 10s

    rule_files:
      - '/etc/prometheus-rules/*.rules'

    scrape_configs:
       # The job name is added as a label `job=&lt;job_name&gt;` to any timeseries scraped from this config.
      - job_name: 'prometheus'

        # Override the global default and scrape targets from this job every 5 seconds.
        scrape_interval: 5s

        # metrics_path defaults to '/metrics'
        # scheme defaults to 'http'.

        static_configs:
          - targets: ['localhost:9090','12.10.17.6:9100','12.10.17.19:9100'] 
</code></pre>

<p>Can any one suggest how I can achieve this ?</p>

<p>Prometheus supports a Kubernetes service discovery mechanisms, see the <a href="https://prometheus.io/docs/operating/configuration/#%3Ckubernetes_sd_config%3E" rel="nofollow noreferrer">documentation</a> for details.
<br><br>
So instead of the <code>static_configs</code> section, you should add a section similar to this:</p>

<pre><code>scrape_configs:
- job_name: 'kubernetes-service-endpoints'

  kubernetes_sd_configs:
  - role: endpoints

...
</code></pre>

<p>See this <a href="https://github.com/prometheus/prometheus/blob/master/documentation/examples/prometheus-kubernetes.yml#L37" rel="nofollow noreferrer">example configuration file</a> for how it's done.</p>
