How to scrape metrics-server to prometheus outside kubernetes cluster
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Prometheus outside a Kubernetes cluster cannot directly scrape metrics-server in most setups because metrics-server is designed primarily for Kubernetes APIs, not general Prometheus exposition. A practical solution is exposing Kubernetes resource metrics through a Prometheus-compatible endpoint using an adapter or exporter pattern. Security and network access design are as important as query correctness.
Understand Metrics Sources First
metrics-server feeds the Kubernetes metrics API used by autoscaling and kubectl top. It is not a long-term time-series store and does not always expose a scrape-friendly endpoint for external Prometheus.
Prometheus expects HTTP endpoints returning the Prometheus text format.
Recommended Architecture
Common external-scrape pattern:
- inside cluster component fetches Kubernetes metrics API
- component exposes Prometheus-formatted metrics
- external Prometheus scrapes exposed endpoint
You can use kube-state-metrics and node-exporter for many resource metrics, and add custom exporters only for gaps.
Example Service Exposure
Expose exporter service through controlled endpoint.
For production, prefer Ingress or private load balancer with TLS and auth rather than raw NodePort.
External Prometheus Scrape Config
Validate target reachability and firewall rules from Prometheus host.
Authentication and RBAC
Exporter inside cluster often needs permissions to read metrics APIs. Grant minimal RBAC scope. Avoid cluster-admin defaults for convenience.
Also protect external endpoint with network policy, mTLS, and allow-listing where possible.
Troubleshooting Checklist
- verify exporter pod running
- verify service endpoint reachable
- verify Prometheus target status page
- inspect scrape errors and HTTP status
- confirm RBAC allows metrics reads
A staged checklist is faster than editing many components simultaneously.
Prefer Native Prometheus Stack Where Possible
For full Kubernetes monitoring, Prometheus typically runs inside cluster and remote-writes to external systems. External-only scrape designs can work, but they add network complexity and authentication overhead. Pick architecture based on operational constraints and compliance requirements.
Example Exporter Deployment Skeleton
A simple deployment can expose transformed metrics inside the cluster.
Keep image and RBAC policy aligned with your security baseline.
Network Topology Options
For external Prometheus, common options include private load balancer, VPN-linked service discovery, or pull-through gateway in DMZ networks. Choose topology that matches compliance requirements and avoids public exposure of internal metrics endpoints.
Alerting Validation
After scrape is successful, add a test alert rule on exporter up-metric to confirm end-to-end visibility from collection to alerting pipeline. Monitoring without alert validation can fail silently during incidents.
TLS and Certificate Management
If external Prometheus scrapes over HTTPS, automate certificate rotation and validate trust chains. Expired certificates are a frequent cause of sudden scrape failures in otherwise healthy monitoring stacks.
Capacity Planning
Exporter endpoints should be sized for scrape interval and target cardinality. Under-provisioned exporters can become bottlenecks and produce intermittent timeout errors.
Common Pitfalls
- Assuming metrics-server is directly scrape-ready for external Prometheus.
- Exposing metrics endpoints publicly without authentication.
- Skipping RBAC hardening for exporter service accounts.
- Using NodePort in production without network controls.
- Debugging scrape failures without checking Prometheus target status first.
Summary
- Metrics-server is not usually a direct external Prometheus scrape target.
- Use exporter or adapter layers to expose Prometheus-formatted metrics.
- Secure endpoint access with RBAC, network controls, and TLS.
- Validate reachability and scrape status step by step.
- Prefer architecture that balances observability, security, and operational simplicity.
Related reading
- How to see logs of terminated pods
- How to see Pod logs a container name must be specified for pod... choose one of wait main
- how to see the pod and veth relationship in kubernetes
- How to set dynamic values with Kubernetes yaml file
- How to search for plain text in cloudwatch logs insights?
- How to see all running Amazon EC2 instances across all regions?
- How to set egress ipBlock for multiple IPs and ports?
- How to set kubernetes secret as as connection string password in .NET Core?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.