Skip to content

Prometheus Service Discovery Not Finding Targets Fix

DodaTech Updated 2026-06-24 3 min read

In this tutorial, you'll learn about Prometheus Service Discovery Not Finding Targets Fix. We cover key concepts, practical examples, and best practices.

Your Prometheus service discovery finds zero targets — the SD provider is configured but returns 0 targets under Status → Service Discovery. The API credentials are wrong, the SD role is misconfigured, or the services are not labeled for discovery.

The Problem

scrape_configs:
  - job_name: 'kubernetes-pods'
    kubernetes_sd_configs:
      - role: pod
Service Discovery: kubernetes-pods — 0 targets

Prometheus uses the in-cluster service account to discover pods. If the service account lacks permissions or the cluster is not reachable, zero targets are returned.

Step-by-Step Fix

1. Verify service account permissions

# RBAC for Prometheus service account
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: prometheus
rules:
  - apiGroups: [""]
    resources: ["pods", "services", "endpoints", "nodes", "nodes/metrics"]
    verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: prometheus
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: prometheus
subjects:
  - kind: ServiceAccount
    name: prometheus
    namespace: monitoring

2. Configure SD providers correctly

scrape_configs:
  # Node discovery
  - job_name: 'kubernetes-nodes'
    kubernetes_sd_configs:
      - role: node

  # Pod discovery
  - job_name: 'kubernetes-pods'
    kubernetes_sd_configs:
      - role: pod
    relabel_configs:
      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
        regex: "true"
        action: keep

  # Service discovery
  - job_name: 'kubernetes-services'
    kubernetes_sd_configs:
      - role: service

3. Check SD status in Prometheus UI

# Open Prometheus UI → Status → Service Discovery
# Check each SD provider for:
# - Number of discovered targets
# - Last error message
# - Labels available per target

# API endpoint for SD status
curl http://prometheus:9090/api/v1/status/discovery

4. Configure Consul SD

scrape_configs:
  - job_name: 'consul-services'
    consul_sd_configs:
      - server: 'localhost:8500'
        datacenter: 'dc1'
        services:
          - 'web'
          - 'api'
    relabel_configs:
      - source_labels: [__meta_consul_service]
        regex: '(.*)'
        target_label: service
        replacement: '${1}'

5. Configure EC2 SD

scrape_configs:
  - job_name: 'ec2-instances'
    ec2_sd_configs:
      - region: us-east-1
        access_key: 'AKIA...'
        secret_key: '...'
        port: 9100

Expected output:

Service Discovery: kubernetes-pods — 150 targets
  Labels: __meta_kubernetes_pod_label_app, __meta_kubernetes_pod_label_version, ...
  Targets: 10.0.0.1:8080, 10.0.0.2:8080, ...

Prevention Tips

  • Verify RBAC permissions for Kubernetes SD
  • Check Prometheus server logs for SD errors
  • Use Prometheus UI → Status → Service Discovery to debug
  • Use relabel_configs to filter discovered targets
  • Start with one SD provider before adding more

Common Mistakes with service discovery

  1. Forgetting deriving (Show, Eq) on custom data types needed for debugging
  2. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  3. Using head and tail instead of pattern matching, causing runtime errors on empty lists

These mistakes appear frequently in real-world PROMETHEUS code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why does Kubernetes SD find pods but they have wrong ports?

Kubernetes pods can expose multiple ports. Prometheus uses the first container port by default. Use relabeling with __meta_Kubernetes_pod_container_port_number and __meta_Kubernetes_pod_container_port_name to select the correct port.

Can I use multiple SD providers in one scrape config?

Yes, Prometheus merges targets from all SD providers in a single scrape_config. This is useful for hybrid environments where some targets are in Kubernetes and others are in Consul or EC2.

How often does service discovery refresh?

The default refresh interval is 30s for most SD providers. Configure with refresh_interval in the SD config: kubernetes_sd_configs: { role: pod, refresh_interval: 30s }. Shorter intervals detect new targets faster but increase API calls.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro