Ingress routing rules to access prometheus server
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Prometheus usually runs as an internal service inside a Kubernetes cluster, but teams often want browser access for dashboards, queries, and troubleshooting. The safe way to expose it is to route HTTP traffic through an Ingress resource instead of opening the pod directly.
Exposing Prometheus Through Ingress
An Ingress rule maps an external host or path to a Kubernetes Service. For Prometheus, that service usually points at port 9090. The Ingress controller, such as NGINX, Traefik, or HAProxy, watches the Ingress resource and configures the actual reverse proxy.
The basic flow is:
- Prometheus listens inside the cluster.
- A
Servicegives it a stable virtual address. - An
Ingressmaps an external URL to that service. - DNS points the hostname to the Ingress controller.
A minimal service and ingress pair looks like this:
With that configuration, traffic sent to prometheus.example.com is forwarded to the prometheus service.
Host-Based And Path-Based Routing
Host-based routing is usually the cleanest option because Prometheus expects to serve content from a consistent root path. A dedicated host such as prometheus.example.com is easier than sharing a generic monitoring host with path rewrites.
If you must expose Prometheus under a path such as /prometheus, you need two aligned settings:
- the Ingress must route
/prometheus - Prometheus must know its external path prefix
Example:
Prometheus also needs matching startup flags:
Without these flags, static assets and redirects often break because Prometheus still thinks it lives at the root URL.
Adding TLS And Basic Protection
Prometheus is operationally sensitive. If you expose it publicly, use TLS and some form of authentication or network restriction.
If your controller supports authentication annotations, you can add them there. Another common pattern is to keep Prometheus internal and expose it only through a VPN, private load balancer, or identity-aware proxy.
How To Verify The Route
After applying the resources, verify each layer separately instead of guessing.
Check the service:
Check the ingress:
If DNS is not ready yet, you can still test by forcing the Host header:
That tells you whether the controller is routing correctly before public DNS is updated.
Common Pitfalls
The most common mistake is routing to the wrong service port. Prometheus often listens on 9090, but some charts expose a differently named service or an alternate port mapping. Always inspect the actual service definition.
Another issue is path prefix mismatch. If you publish Prometheus below /prometheus but do not set --web.external-url, parts of the UI redirect to the wrong path or return 404.
Controller-specific annotations are also easy to misuse. A rewrite rule that works in NGINX may not work in Traefik. Keep your Ingress manifest aligned with the controller you actually installed.
Finally, avoid exposing Prometheus anonymously on the public internet. Metrics often reveal hostnames, workload names, and internal topology. Route protection is part of the deployment, not an optional afterthought.
Summary
- Use a Kubernetes
Serviceas the stable backend for Prometheus and route to it through anIngress. - Prefer host-based routing such as
prometheus.example.combecause it is simpler than path rewriting. - If you use a path prefix, configure both the Ingress rule and Prometheus external URL settings.
- Add TLS and access controls before exposing monitoring endpoints outside the cluster.
- Validate service, ingress, and DNS separately so routing failures are easier to isolate.

