> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Additional Scrape Configs

> Explains how to add Prometheus scrape jobs via kube-prometheus-stack additionalScrapeConfigs and recommends using ServiceMonitors as the preferred operator native approach

So we got our application deployed onto Kubernetes:

```yaml theme={null}
apiVersion: v1
kind: Service
metadata:
  name: api-service
  labels:
    job: node-api
```

Now it's time to make Prometheus aware of these new targets. There are two main approaches:

* The less ideal approach: use the chart's `additionalScrapeConfigs` to append raw Prometheus scrape jobs to the server configuration.
* The preferred approach: use ServiceMonitors, the Prometheus Operator–native, declarative way to add targets.

Below I show the high-level steps for the less-preferred approach, so you understand what to change. It will work, but there are caveats.

<Callout icon="warning" color="#FF6B6B">
  Using `additionalScrapeConfigs` means you are appending raw Prometheus scrape configuration. The chart does not validate these entries and upgrades could potentially break if the scrape config is incompatible with future Prometheus changes. Prefer ServiceMonitors for a more robust, operator-friendly solution.
</Callout>

1. Dump the chart's default values so you can edit them:

```bash theme={null}
helm show values prometheus-community/kube-prometheus-stack > values.yaml
```

2. Open `values.yaml` and search for `additionalScrapeConfigs`. This field lets you append Prometheus scrape jobs. The chart will not validate the contents, so ensure the jobs are valid Prometheus configuration blocks.

Here is an example of how you can add additional scrape jobs (this is one valid way to format the jobs; adapt jobs and relabeling rules to your environment):

```yaml theme={null}
additionalScrapeConfigs:
- job_name: kube-etcd
  kubernetes_sd_configs:
  - role: node
  scheme: https
  tls_config:
    ca_file: /etc/prometheus/secrets/etcd-client-cert/etcd-ca
    cert_file: /etc/prometheus/secrets/etcd-client-cert/etcd-client
    key_file: /etc/prometheus/secrets/etcd-client-cert/etcd-client-key
  relabel_configs:
  - action: labelmap
    regex: __meta_kubernetes_node_label_(.+)
  - source_labels: [__address__]
    action: replace
    target_label: __address__
    regex: '([^;]+):(\d+)'
    replacement: '${1}:2379'

# Example job for a Kubernetes service (adapt service name/port labels to your cluster)
- job_name: api-service
  kubernetes_sd_configs:
  - role: endpoints
  relabel_configs:
  - source_labels: [__meta_kubernetes_service_name, __meta_kubernetes_endpoint_port_name]
    action: keep
    regex: 'api-service;http'
```

Notes about the example:

* The `kubernetes_sd_configs` and `relabel_configs` entries follow Prometheus server configuration syntax.
* You must ensure the configuration is valid YAML and valid Prometheus config; the chart will not validate it for you.
* Replace the service/port names and relabel rules to match how your application is exposed in Kubernetes.

3. Apply the updated values by upgrading the Helm release:

```bash theme={null}
helm upgrade prometheus prometheus-community/kube-prometheus-stack -f values.yaml
```

After the upgrade completes, Prometheus should reload with the appended scrape jobs and begin scraping the newly added targets.

<Callout icon="lightbulb" color="#1CB2FE">
  ServiceMonitors provide a declarative, Operator-native way to add targets to Prometheus and are generally the recommended approach.
</Callout>

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/prometheus-certified-associate-pca/module/bb958f66-38c3-41ed-ae2f-7a4ee96c4d66/lesson/c0644cd7-27af-4637-853b-61f7cb946ca8" />
</CardGroup>
