Write relabeling that only scrapes pods annotated with `prometheus.io/scrape: "true"`.

IntermediateConceptPrometheus Architecture
Answer
- job_name: annotated-pods
  kubernetes_sd_configs:
    - role: pod
  relabel_configs:
    - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
      action: keep
      regex: "true"
    - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
      action: replace
      target_label: __metrics_path__
      regex: (.+)
    - source_labels: [__meta_kubernetes_namespace]
      target_label: namespace
    - source_labels: [__meta_kubernetes_pod_name]
      target_label: pod

Annotation names are sanitized: dots and slashes become underscores. With the Prometheus Operator we use ServiceMonitor/PodMonitor instead.

All Monitoring & Observability questions Roadmap: Monitoring & alerting

More on Prometheus Architecture