K8s Service Discovery relabel configs

25 views
Skip to first unread message

Rasmus Rüngenen

unread,
Feb 11, 2021, 12:38:56 PM2/11/21
to Prometheus Users
Hello!

I have pods that have annotations containing the portNames that match the ports Prometheus should scrape per pod. I wanted to know if it is possible using the Kubernetes SD to relabel configs so that 
 - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_portName]
          action: drop
          regex: __meta_kubernetes_pod_container_port_name

would only scrape the ports that have a specific portName defined in the annotations?
This workaround is introduced due to the condition that Prometheus creates a new target for each port that a container has while using the pod role in K8s SD whereas only one of them exposes Prometheus metrics. 

So far I have tried different ways and I haven't found good documentation if it is possible to use labels in regex actions. 

Thanks in advance,
Rasmus
Reply all
Reply to author
Forward
0 new messages