Prometheus 配置忽略 Kubernetes 中特定命名空间的指标抓取

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

有没有办法将 prometheus 配置为忽略属于特定命名空间的所有资源的抓取指标?我无法通过阅读文档来弄清楚。

您可以使用 drop 操作删除 relabel_config 的目标。来自 documentation:

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

示例:

  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