Prometheus automatic scraping is a game-changer for Kubernetes environments: it dynamically discovers metrics exporter endpoints without requiring manual configuration every time a new workload drops. But what happens when your core infrastructure relies on databases or legacy services running outside the cluster?
While this setup was natively designed for internal Kubernetes workloads, you can successfully extend automatic scraping to external servers. You do not need to abandon Kubernetes-native abstractions or hardcode static scrape targets in your Prometheus configuration.
External Services Discovery With Prometheus ServiceMonitor demonstrates how to exploit the Prometheus Operator's ServiceMonitor to dynamically discover and scrape metrics from external servers. As a practical example, we will configure a production-grade monitoring pipeline for external PostgreSQL nodes and system metrics, implementing enterprise security best practices along the way.