Prometheus service discovery for Kubernetes, Consul and clouds

Prometheus finds scrape targets through service discovery, and the design choices you make for each source decide how your labels, cardinality and ownership hold up as the estate grows.

On this page

How Prometheus service discovery finds targets in a changing estate

Service discovery lets Prometheus pull metrics from targets it finds at runtime, instead of from a list someone maintains by hand. That matters when autoscaling, rolling deployments and container reschedules add and remove instances faster than a configuration file can be edited. A static list of host names works for a fixed set of virtual machines. It fails quietly when a pod is replaced or a scaling group adds nodes, because the new instances are never scraped and the gap shows up only when someone looks for a metric that is missing.

Prometheus collects metrics by pulling them over HTTP from each target on a schedule. The set of targets comes from one of two sources: service discovery or static configuration. The service discovery mechanisms the project supports include Kubernetes, Consul, cloud provider APIs, DNS, generic HTTP endpoints and file-based discovery, where an external process writes target files that Prometheus reloads. Static configuration remains the simplest choice for a small, stable set of targets. Teams usually need service discovery once target identity depends on the platform rather than on a host name someone wrote down.

The Prometheus documentation describes these two sources but does not say which mechanism to choose. That decision belongs to the team, based on where workloads actually run. A Kubernetes cluster is discovered through the cluster API, a Consul estate through its service catalog, and a cloud estate through the provider's instance metadata. Before choosing, confirm three things in your own environment: which system is the source of truth for what should be running, whether Prometheus can reach that system with a read-only identity, and how often the list changes. If two systems describe the same workloads, such as Consul registrations and Kubernetes services, decide which one drives scraping, or you will collect duplicate series under different labels.

Discovery finds more targets than you want to scrape, so the discovered labels are only the input. Relabeling rules decide which targets are kept, how they are renamed and which labels survive into stored series. Those rules are the place to control cardinality, and the next sections cover them in detail. Plan for discovery failures too: if the discovery API is unreachable, Prometheus keeps the last known targets, so a broken integration can look healthy until someone checks the target status page.

Choosing a discovery source for Kubernetes, Consul, clouds, DNS, HTTP and files

Kubernetes service discovery reads pods, services, endpoints, endpoint slices, ingresses and nodes from the API server, so targets appear and disappear as workloads are scheduled, scaled and replaced. It fits clusters where workloads carry annotations or labels that describe how they should be scraped, and where the platform team wants monitoring to follow deployments without editing Prometheus configuration by hand.

  • Discovery roles: Choose the role (for example pod, service, endpoints or node) that matches the port and address you need to scrape, and confirm how each role exposes labels in the kubernetes_sd_configs reference.
  • API access: Prometheus needs a service account with read permissions on the objects it discovers. Confirm the RBAC rules and whether the server runs inside the cluster or reaches the API from outside.
  • Namespace scope: Restricting discovery to selected namespaces reduces the permissions and the number of targets. Confirm the namespace selection options before you grant cluster-wide access.
  • Relabeling for opt-in: Teams commonly keep only targets with an opt-in annotation, then rewrite addresses and labels with relabel_configs. Confirm the exact annotation names your teams will use.
  • Cluster-level listing load: Discovery watches the API, so large clusters add load on the control plane. Confirm the impact with the platform team before enabling broad roles.

Before rollout, confirm the RBAC scope, the namespace list and the annotation contract with the platform team in writing.

How relabeling rules keep labels consistent and cardinality under control

Relabeling is where a discovery design becomes a labeling policy. Prometheus runs relabel_configs on labels found during discovery, before a target is scraped, and metric_relabel_configs on each sample after the scrape and before it is stored or forwarded. The first stage decides which targets exist and what their identity is. The second stage decides which series the database keeps. Teams that treat them as one step usually end up with dashboards that break when a service renames a label, or with a storage bill that grows with every deployment.

The most useful early pattern is selection by intent. In Kubernetes, the discovery stage exposes pod and service metadata as __meta_kubernetes_* labels, so a rule can keep only pods that carry an agreed annotation or label such as a scrape flag owned by your platform team, then copy the namespace, app and job name into stable labels. Keep the instance label consistent across Kubernetes, Consul and cloud targets, and drop the __meta_* source labels once they have been used. Ask your team to write down which label names are contract (used in alerts and dashboards) and which are internal, and confirm that every discovery job emits the contract set.

Cardinality risk comes from values that never repeat. Pod UIDs, container IDs, request paths with identifiers in them, user IDs, and client IP addresses each create a new series every time they change, and a rolling deployment changes pod UIDs constantly. Use metric_relabel_configs with labeldrop or labelkeep to remove these labels from samples, and use action: drop on metric names that a team has not approved. Where a path label is needed, normalize it into a route template in the application or in a rule rather than keeping the raw value. Your check is a query on the series count per metric and per job, run before and after each change, and a review of any label whose value set grows with traffic.

Two decisions need owner sign-off. First, whether dropping a label in relabeling is acceptable for the alerts and recording rules that depend on it, because relabeling is applied before rules see the data. Second, who may change relabeling rules, since a single edit can silently remove a series that an alert needs. Keep discovery and relabeling configuration in version control, test changes against a staging Prometheus, and confirm with your vendor documentation for the Prometheus version you run how relabel actions behave in that release, since edge cases differ between releases.

How to set up service discovery in a production Prometheus

This sequence takes discovery from an inventory of target sources to a staged rollout, so each scrape job has a clear owner, least-privilege access, consistent labels and a verified target list before it reaches production.

  1. Inventory target sources and their owners

    Before writing any configuration, list every place targets will come from: Kubernetes clusters, Consul catalogs, cloud accounts, DNS records, HTTP endpoints and static files. For each source, record the team that owns it, the identity Prometheus will use to read it, and the network path from the Prometheus host. Confirm ownership with the people who run each source, not only with the team that runs Prometheus. The step is done when every source has a named owner, an access method and a agreed contact for changes that would affect scraping.

  2. Pick one discovery mechanism per source

    For each source, choose a single discovery mechanism, such as the Kubernetes or Consul service discovery configuration, a cloud provider mechanism, DNS, HTTP, or file-based discovery as a fallback. Running two mechanisms against the same targets produces duplicate series and confusing up metrics. Where a platform team already publishes a catalog, prefer reading that catalog over building a parallel one. The output is a short table mapping each source to one mechanism and one scrape job name. Confirm each mechanism's options against the Prometheus configuration reference for the version you run, because option names change between releases.

  3. Write scrape jobs with minimum permissions

    Create one scrape job per source and give each job its own credentials. For Kubernetes, bind a role that allows listing and watching only the resources and namespaces the job needs. For Consul, cloud and HTTP sources, use a read-only token or service identity scoped to the catalog or resources in question. Store secrets in files readable only by the Prometheus service account, not inline in version-controlled configuration. The check is an access test run with the same credentials: discovery should return the expected targets, and a request for an out-of-scope resource should be denied.

  4. Add relabeling for consistent labels and drop noise

    Use relabel_configs to set a fixed set of labels such as environment, cluster, team and service, and use metric_relabel_configs to drop series you do not need, including high-cardinality labels added by instrumentation. Keep label names identical across all jobs so queries and alert rules work everywhere. Decide early which source labels become permanent and which are dropped, because changing them later breaks existing dashboards and recording rules. The check is a dry run on a sample of targets: the resulting label set should match the agreed naming list, and no target should lose its job or instance label.

  5. Validate targets and configuration before reload

    Run promtool check config against the new configuration file and fix every error before going further. Then open the Targets page in the Prometheus web UI, filter by job, and confirm that each expected target is discovered, that its health is up, and that its labels match the relabeling plan. Also check the Service Discovery page for targets that were discovered but dropped by relabeling, since that shows whether filters are removing more than intended. The step is complete when the target count matches the inventory from step one within expectations the owner has confirmed.

  6. Review the reload path before enabling it

    Reload endpoints are disabled by default. The --web.enable-lifecycle flag enables reload and shutdown endpoints, which lets anyone who can reach the HTTP port change the running process state. Treat enabling it as a security decision: confirm who can reach the listener, whether TLS and authentication are in place, and whether a supervised process restart or signal-based reload is enough. If you do enable it, document the decision and restrict network access. The check is a written decision record approved by the security owner, plus a test that an unauthenticated request to the reload endpoint is refused.

  7. Roll out in stages and watch for drift

    Deploy the configuration to a non-production Prometheus first, then to one production cluster or site, and only then to the rest. After each stage, compare the target count, series count and up metrics with the previous state, and check that alert rules still evaluate against the new labels. Keep the previous configuration file so you can restore it quickly. Ask the owners of each source to confirm that their services appear as expected. The rollout is done when every source is scraped from the production server, the previous configuration is archived, and the owners have signed off.

Design risks that break discovery at scale

Service discovery makes Prometheus follow whatever the orchestrator, Consul catalog or cloud API reports, so a small configuration mistake can multiply targets, labels and credentials quickly. The cards below cover the failure modes that show up most often once a monitoring estate grows, each paired with the design decision that prevents it.

Over-broad discovery scrapes unintended targets

A discovery block that matches every pod, service or instance in a cluster or account will scrape things nobody meant to monitor, including sidecars, batch pods and test environments. The symptom is a sudden jump in targets and in scrape load after a new namespace or account is added. Filter at discovery time with explicit keep rules on namespaces, tags or annotations, and confirm the target count against an agreed inventory before each rollout.

Unstable label values cause churn

Labels built from values that change on every deployment, such as pod names, container IDs or auto-assigned IP addresses, create a new series each time the value changes. The symptom is steadily rising series counts and dashboards that show gaps at every rollout. Map discovery metadata to stable labels such as workload, team and environment, and drop the volatile ones in relabeling before ingestion.

New labels drive cardinality growth

Each new discovery label multiplies the number of series a metric can produce, and a label copied from a high-variety source such as a request path, user ID or image digest can grow the series count without bound. The symptom is rising memory use and slower queries after a team adds a label. Review every label that relabeling keeps, and set a rule that new discovery labels need an owner and a stated purpose.

Discovery credentials with broad read access

Prometheus needs to list and read targets from the Kubernetes API, Consul or a cloud provider, and a service account or role granted cluster-wide or account-wide read access can expose far more metadata than monitoring requires. The symptom is a credential that can read secrets, other tenants or unrelated resources. Scope the role to the namespaces, services or tags Prometheus scrapes, and document who can read the credential and where it is stored.

Lost targets after a backend change

Moving from one discovery backend to another, such as changing Consul catalog tags, renaming cloud instance tags or migrating a cluster, can make previously discovered targets disappear without any error. The symptom is a drop in the up count and silent gaps in dashboards. Run the old and new discovery configuration side by side, compare target sets before cutover, and alert when the number of discovered targets falls sharply.

Duplicate series from overlapping jobs

Two scrape jobs that match the same endpoint, for example a Kubernetes pod discovered both by role and by a separate service job, produce duplicate series that double counts in sums and rates. The symptom is totals that are roughly twice the expected value for one service. Give each scrape job a distinct purpose in its selectors, and check that each target and series identity is unique across jobs before alerts depend on the numbers.

How discovered targets flow through relabeling into storage

The diagram starts at the discovery sources, which can be the Kubernetes API, Consul, a cloud provider API, DNS, an HTTP endpoint or files. Each source feeds one target set, and relabel_configs decide which targets are scraped and what their labels become before any request is sent. Scraped samples then pass through metric_relabel_configs, which is the last point to drop series or fix labels before local storage or remote write. Check the credential boundary: the service discovery credentials can read the cluster or cloud inventory, so they belong inside the boundary and should be scoped to read-only access.

Discovery sources, relabeling and storage hand-offs in one Prometheus pipeline.

Which discovery option fits each environment

This table compares the main Prometheus discovery mechanisms by the environment they suit, what each one needs from your network and identity setup, and what to confirm before you commit. Read each row as a decision: find the environment you run, then check the requirements and open questions before choosing a mechanism. Most estates combine two or three options, so plan the mix before writing scrape configs.

EnvironmentWhen it fitsNeeds from network and identity, and what to confirm first
Kubernetes clustersWorkloads run as pods and services that change often, and you want Prometheus to follow them without manual edits.Prometheus needs API access to the cluster with a service account and RBAC rules that allow listing and watching pods, services, endpoints and nodes. Confirm which namespaces it may read and whether network policies allow scrapes to pod ports.
Consul-registered servicesServices already register in Consul and the catalog is the source of truth for what should be scraped.Prometheus must reach the Consul agent or server API and hold an ACL token with read access to the services it scrapes. Confirm token scope, datacenter and namespace settings, and whether the catalog includes services that should not be monitored.
Cloud virtual machinesInstances come and go in a cloud account and carry tags or labels that identify their role.Prometheus needs an identity with permission to describe instances in the relevant accounts, regions and projects, and network paths to instance metrics ports. Confirm how the identity is granted (instance role, workload identity or key), and which tags are reliable enough to filter on.
DNS-published servicesServices are published as DNS records, such as SRV records, and the DNS zone is maintained by your platform or network team.Prometheus must query the DNS resolvers that hold the records, and records must include the port and target you expect. Confirm record ownership, TTL behavior during changes, and whether internal and external resolvers return different answers.
HTTP service registriesAn internal registry or inventory service exposes a JSON list of targets that your own tooling maintains.Prometheus must reach the registry over HTTP with TLS and any credentials it requires. Confirm the response format, the owner of the registry, what happens when it is unavailable, and who approves changes to its contents.
Static file listsThe target set is small, stable or managed through a configuration pipeline, and you want a simple and auditable source.Prometheus reads target files from its host, so the files must be deployed and reloaded through your change process. Confirm who owns the files, how they are reviewed, and how stale entries are removed, since nothing removes them automatically.

Securing discovery credentials and target access

Service discovery gives Prometheus a standing view of your infrastructure, and the credentials and endpoints behind that view deserve the same care as the metrics themselves. The cards below cover who can read discovery sources, how discovery credentials are protected, which Prometheus endpoints can be turned against your network, and how authentication and SSO are placed in front of the server.

Least-privilege read access to APIs

Discovery needs only to list and read targets, not to change anything. For Kubernetes, bind the Prometheus service account to read-only roles scoped to the namespaces it scrapes. For Consul and cloud providers, create a dedicated identity whose policy allows listing services, instances or tags and nothing else. Ask your platform team to confirm that the discovery identity cannot create, modify or delete resources, and review its permissions whenever a new namespace, account or region is added.

Protecting discovery credentials

Tokens, API keys and client certificates used for discovery are secrets that sit in configuration files, so they need storage and rotation controls. Keep them out of version control, mount them as files with restricted permissions, and use short-lived credentials where your orchestrator or cloud provides them. Confirm with your team who can read the Prometheus configuration directory, since anyone who reads a discovery token can call the discovery API directly.

Exporter target abuse through URL parameters

The Prometheus security model warns that exporters such as SNMP and Blackbox take their targets from URL parameters. Anyone with HTTP access to these exporters can make them send requests to arbitrary endpoints, which can reach internal systems you did not intend to expose. Restrict network access to exporter ports, limit which hosts Prometheus can reach through them, and treat discovered target lists as an access boundary.

Security model docs

Basic authentication requires TLS

Prometheus supports HTTP basic authentication with bcrypt-hashed passwords, but basic authentication without TLS sends credentials in cleartext. Pair any basic authentication with TLS, which Prometheus also supports with TLS 1.2 as the minimum version, and use client certificate authentication where your environment allows it. Check every scrape job and remote endpoint that carries credentials, because a single job configured without TLS exposes its password on the network.

Security model docs

Authenticating proxy for the web UI

Prometheus has no built-in single sign-on, and its security model notes there is no built-in CSRF protection on mutating endpoints. Place an authenticating reverse proxy in front of the web UI and API so that users sign in through your identity provider before reaching Prometheus. Confirm that the proxy also protects direct API paths, and that admin endpoints stay disabled unless you enable them deliberately.

Security model docs

Questions buyers ask about Prometheus service discovery

How much does Prometheus service discovery cost to implement?

Prometheus itself carries no license fee, because it is licensed under Apache-2.0 and has no paid enterprise edition, so the cost comes from three places: infrastructure to run the servers, implementation effort to design discovery and relabeling, and the people who operate it afterward. Implementation is usually a one-time cost that covers discovery design, relabeling rules, access setup and documentation. Infrastructure and staff time recur. Ask any partner for a quote built from a written scope that lists the discovery sources in play (Kubernetes, Consul, cloud APIs, DNS, files), the number of clusters and accounts, and who owns label standards. DeployOpen does not publish a price list, and a quote follows from that written scope.

How long does it take to set up service discovery and what drives the timeline?

The timeline depends on how many discovery sources you run and how settled your label conventions are. A single Kubernetes cluster with pod annotations moves faster than a mix of Kubernetes, Consul, several cloud accounts and file-based targets, because each source needs its own credentials, filters and test runs. Label design is often the slowest part, since teams must agree on names for environment, service and owner before relabeling is written. Validation against real targets, and a review of the resulting series count, add time. Confirm the expected duration against a written scope rather than a generic estimate.

What does the client team need to provide for discovery work?

The work needs access and decisions from your side before configuration starts. Typical inputs are:

  • Kubernetes: a service account or kubeconfig with read access to the namespaces and resources Prometheus will discover.
  • Consul: an ACL token with permission to read the catalog and health data for the services in scope.
  • Cloud providers: IAM roles or service principals that allow listing instances, tags and endpoints in each account.
  • Labels: named owners who approve the standard label set and decide how teams tag their workloads.

Also confirm network paths from Prometheus to each target and where secrets for those roles will be stored. Ask the partner to list these inputs in the scope document.

Can our own platform team set up Prometheus discovery without a partner?

Yes, a capable platform team can configure Kubernetes or static file discovery without outside help, especially for one cluster and a small set of labels. The harder parts are cross-source consistency, cloud roles with least privilege, and relabeling that keeps cardinality under control across many teams. Teams that run Prometheus only occasionally often benefit from a short design review before rollout. Decide based on how many sources you run, whether anyone has operated Prometheus in production, and how much time your engineers can spare for testing and documentation.

Can a relabeling change break our existing alerts and dashboards?

Yes. Relabeling changes the labels attached to every series, so an alert rule or dashboard that filters on a label such as job, instance or a custom team label can stop matching after a change. Discovery changes can also alter the set of targets, which changes totals and rates. Reduce this risk by running new relabeling on a staging Prometheus, comparing the series names and label sets before and after, and updating rules in the same change. Keep the old label names for a transition period where possible. Verify each alert with a test query before retiring the old version.

How does service discovery relate to Kubernetes and OpenTelemetry integrations?

Kubernetes discovery is one of several discovery mechanisms built into Prometheus, so it sits alongside Consul, cloud, DNS, HTTP and file-based discovery rather than replacing them. OpenTelemetry is a separate telemetry pipeline that can send metrics to Prometheus, either through its own export path or through Prometheus receiving OTLP data, so discovery answers which targets Prometheus pulls from, while OpenTelemetry answers how applications and collectors emit telemetry. Decide early which path owns each workload to avoid duplicate series. The Prometheus integrations group covers those connections in more depth.

Does Prometheus discovery provide access control or audit logging for who reads metrics?

Prometheus discovery controls which targets are scraped, not who can read the results. The Prometheus security model covers TLS, client certificates and basic authentication for the server, but it has no built-in single sign-on, so SSO is normally added with an authenticating reverse proxy. Discovery credentials, such as Kubernetes tokens and cloud roles, should be scoped to read-only access and stored in your secrets system. Ask any partner to show how each credential is limited and where its use is logged.

How DeployOpen works on this

DeployOpen plans and implements Prometheus service discovery inside your own clouds, clusters and data centers, with the target inventory, relabeling rules and access paths agreed before configuration starts. Each engagement is fixed-scope, so the discovery sources, label standard and deliverables are written down and reviewed by your platform and security teams.

How we scope

  • Inventory the Kubernetes clusters, Consul datacenters, cloud accounts and DNS zones that Prometheus must discover targets in
  • Agree the label standard, relabeling rules and cardinality limits that every discovered target must follow
  • Define which network paths, service accounts and read permissions the Prometheus servers need for each discovery source

How we build

  • Configure each discovery mechanism in a test environment and confirm the target lists match the expected services
  • Write relabeling rules that drop unneeded targets, normalize job and environment labels, and limit high-cardinality labels
  • Test discovery changes under scale and failure conditions, such as a Consul or API server outage, before production rollout

How we hand over

  • Deliver the discovery configuration as versioned files, with a written reference for each source and its relabeling logic
  • Document the label schema, naming conventions and the owner of each discovery source for your platform team
  • Walk your operators through verifying targets, reading discovery status pages and troubleshooting targets that stop reporting

How we support

  • Ongoing support, upgrades and continuous testing are available as a retainer after handover
  • Review new clusters, accounts or services against the label standard before they reach production dashboards
  • Ask any provider for a written scope that names discovery sources, label rules, environments and acceptance tests before signing

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.