Exclude Kubernetes namespaces from prometheus scraping

Viewed 884

I have deployed Prometheus using the community helm chart and would like to scrape the metrics from a specific namespace and drop the metrics from all the other namespaces. I have used the below scrape config, but it doesn't seem to work. Also tried using Drop action.

    - job_name: 'kubernetes-pods'
      kubernetes_sd_configs:
        - role: node
      relabel_configs:
        - action: keep
          source_labels: [__meta_kubernetes_namespace]
          target_label: accounts 
2 Answers

Try this:

- job_name: 'kubernetes-pods'
  kubernetes_sd_configs:
  - role: endpoints
  namespaces:
    names:
    - my-namespace-to-monitor
Related