Search code examples
kubernetesconfigurationmonitoringprometheusistio

Prometheus config to ignore scraping of metrics for a specific namespace in Kubernetes


Is there a way to configure prometheus to ignore scraping metrics for all the resources belonging to a particular namespace? I am not able to figure it out by reading the documentation.


Solution

  • You can drop targets with relabel_config by using drop action. From the documentation:

    drop: Drop targets for which regex matches the concatenated source_labels.

    Example:

      relabel_configs:
      # This will ignore scraping targets from 'ignored_namespace_1', 
      # 'ignored_namespace_2', and 'ignored_namespace_N'.
      - source_labels: [__meta_kubernetes_namespace]
        action: drop
        regex: ignored_namespace_1|ignored_namespace_2|ignored_namespace_N