Prometheus Service Discovery in Kubernetes – Scrape LoadBalancer Ingress Label

I am using the Prometheus Helm chart in my Kubernetes cluster to monitor services. However, I am unable to get Prometheus to discover or scrape the LoadBalancer Ingress field of a Kubernetes service.

Here is the configuration of the service:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Name: postgres-xyz-postgresql-primary
Namespace: xyz
Labels: app.kubernetes.io/component=primary
app.kubernetes.io/instance=postgres-app
app.kubernetes.io/managed-by=Helm
app.kubernetes.io/name=postgresql
app.kubernetes.io/version=17.0.0
helm.sh/chart=postgresql-16.0.1
Annotations: meta.helm.sh/release-name: postgres-app
meta.helm.sh/release-namespace: xyz
Selector: app.kubernetes.io/component=primary,app.kubernetes.io/instance=postgres- app,app.kubernetes.io/name=postgresql
Type: LoadBalancer
IP Family Policy: SingleStack
IP Families: IPv4
IP:
IPs:
LoadBalancer Ingress: aoo000nnbbgghhsdfg-182496858.us-east-1.elb.amazonaws.com
Port: tcp-postgresql 5432/TCP
TargetPort: tcp-postgresql/TCP
NodePort: tcp-postgresql 32599/TCP
Endpoints: 10.0.91.92:5432
Session Affinity: None
External Traffic Policy: Cluster
</code>
<code>Name: postgres-xyz-postgresql-primary Namespace: xyz Labels: app.kubernetes.io/component=primary app.kubernetes.io/instance=postgres-app app.kubernetes.io/managed-by=Helm app.kubernetes.io/name=postgresql app.kubernetes.io/version=17.0.0 helm.sh/chart=postgresql-16.0.1 Annotations: meta.helm.sh/release-name: postgres-app meta.helm.sh/release-namespace: xyz Selector: app.kubernetes.io/component=primary,app.kubernetes.io/instance=postgres- app,app.kubernetes.io/name=postgresql Type: LoadBalancer IP Family Policy: SingleStack IP Families: IPv4 IP: IPs: LoadBalancer Ingress: aoo000nnbbgghhsdfg-182496858.us-east-1.elb.amazonaws.com Port: tcp-postgresql 5432/TCP TargetPort: tcp-postgresql/TCP NodePort: tcp-postgresql 32599/TCP Endpoints: 10.0.91.92:5432 Session Affinity: None External Traffic Policy: Cluster </code>
Name:                     postgres-xyz-postgresql-primary
Namespace:                xyz
Labels:                   app.kubernetes.io/component=primary
                      app.kubernetes.io/instance=postgres-app
                      app.kubernetes.io/managed-by=Helm
                      app.kubernetes.io/name=postgresql
                      app.kubernetes.io/version=17.0.0
                      helm.sh/chart=postgresql-16.0.1
Annotations:              meta.helm.sh/release-name: postgres-app
                      meta.helm.sh/release-namespace: xyz
Selector:                               app.kubernetes.io/component=primary,app.kubernetes.io/instance=postgres-   app,app.kubernetes.io/name=postgresql
Type:                     LoadBalancer
IP Family Policy:         SingleStack  
IP Families:              IPv4
IP:                       
IPs:                      
LoadBalancer Ingress:     aoo000nnbbgghhsdfg-182496858.us-east-1.elb.amazonaws.com
Port:                     tcp-postgresql  5432/TCP
 TargetPort:               tcp-postgresql/TCP
 NodePort:                 tcp-postgresql  32599/TCP
Endpoints:                10.0.91.92:5432
Session Affinity:         None
External Traffic Policy:  Cluster

In my Prometheus scrape configuration, I am using the following job for service discovery:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>- job_name: 'kubernetes-services'
honor_labels: true
metrics_path: /probe
params:
module: [http_2xx]
kubernetes_sd_configs:
- role: service
relabel_configs:
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_probe]
action: keep
regex: true
- source_labels: [__address__]
target_label: __param_target
- target_label: __address__
replacement: blackbox
- source_labels: [__param_target]
target_label: instance
- action: labelmap
regex: __meta_kubernetes_service_label_(.+)
- source_labels: [__meta_kubernetes_namespace]
target_label: namespace
- source_labels: [__meta_kubernetes_service_name]
target_label: service
</code>
<code>- job_name: 'kubernetes-services' honor_labels: true metrics_path: /probe params: module: [http_2xx] kubernetes_sd_configs: - role: service relabel_configs: - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_probe] action: keep regex: true - source_labels: [__address__] target_label: __param_target - target_label: __address__ replacement: blackbox - source_labels: [__param_target] target_label: instance - action: labelmap regex: __meta_kubernetes_service_label_(.+) - source_labels: [__meta_kubernetes_namespace] target_label: namespace - source_labels: [__meta_kubernetes_service_name] target_label: service </code>
- job_name: 'kubernetes-services'
  honor_labels: true

  metrics_path: /probe
  params:
    module: [http_2xx]

 kubernetes_sd_configs:
   - role: service

 relabel_configs:
   - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_probe]
     action: keep
     regex: true
   - source_labels: [__address__]
     target_label: __param_target
   - target_label: __address__
     replacement: blackbox
   - source_labels: [__param_target]
     target_label: instance
   - action: labelmap
     regex: __meta_kubernetes_service_label_(.+)
   - source_labels: [__meta_kubernetes_namespace]
     target_label: namespace
   - source_labels: [__meta_kubernetes_service_name]
     target_label: service

The scrape job does not seem to capture the LoadBalancer Ingress field.

I tried adding the following to the relabel_configs to map the LoadBalancer Ingress to a custom label (loadbalancer_ingress):

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>- source_labels: [__meta_kubernetes_service_annotation_external_dns_hostname]
target_label: loadbalancer_ingress
</code>
<code>- source_labels: [__meta_kubernetes_service_annotation_external_dns_hostname] target_label: loadbalancer_ingress </code>
- source_labels: [__meta_kubernetes_service_annotation_external_dns_hostname]
  target_label: loadbalancer_ingress

However, this doesn’t seem to capture the LoadBalancer Ingress value

Questions:

  1. How can I modify the Prometheus relabel_configs to include the LoadBalancer Ingress field for scraping?

  2. Is there a specific label or field in the kubernetes_sd_configs that maps to the LoadBalancer Ingress field?

  3. Do I need a separate configuration to target LoadBalancer services explicitly?

Additional Info:

Kubernetes version: 1.30
Prometheus Helm chart version: prometheus-26.0.0

Any help in resolving this issue would be greatly appreciated!

  1. How can I modify the Prometheus relabel_configs to include the LoadBalancer Ingress field for scraping?
  2. Is there a specific label or field in the kubernetes_sd_configs that maps to the LoadBalancer Ingress field?

According to Prometheus service sd config, the LoadBalancer Ingress isn’t include as a meta field that will be scraped by Prometheus, the thing that can be scraped is IP field.
I don’t think you could scrape address from Ingress resource either.

I believe what you’re trying to do is differentiate metrics by AWS’s ELB hostname? The hostname of the ELB is generated for you every time you create an Ingress resources so setting a hard code will not be possible.

Maybe using AWS Load Balancer Controller’s annotations such as alb.ingress.kubernetes.io/load-balancer-name on Service or alb.ingress.kubernetes.io/load-balancer-name on Ingress and configure Prometheus to scrape that annotation might be better?
You’d get to identify the load balancer created by AWS with name, while not have to worry about which hostname AWS will generated for you.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật