Solving Prometheus Scraping Errors in kube-prometheus-stack

Address Prometheus scraping errors for etcd, scheduler, controller-manager, and kube-proxy in kube-prometheus-stack by deploying a secure Prometheus Agent DaemonSet as implemented in kps-zeroexposure.

In Kubernetes clusters, Prometheus is widely used for monitoring. But with kube-prometheus-stack Helm chart scraping metrics from control plane components like etcd, kube-scheduler, kube-controller-manager, and kube-proxy can fail due to their metrics endpoints not binding to 0.0.0.0. This issue, detailed in prometheus-community/helm-charts#5695, which highlights an default configuration that restricts access to 127.0.0.1 which is secure but leads to scraping errors. The proposed solution, implemented in the kps-zeroexposure repository, offers a secure approach using a Prometheus Agent DaemonSet. This article explains the issue and how to resolve it securely with the .

The Root of the Scraping Error

By default, Kubernetes control plane components expose their metrics endpoints on 127.0.0.1, making them inaccessible to Prometheus running outside the localhost. A common workaround is to reconfigure these components to bind to 0.0.0.0, but this exposes sensitive metrics to the entire network, posing a security risk. Issue #5695 identifies this problem and suggests a more secure alternative: deploying a lightweight Prometheus agent to scrape metrics locally and forward them to a central Prometheus instance.

Scrape Control Plane Metrics with kps-zeroexposure

The kps-zeroexposure Helm chart deploys a Prometheus Agent DaemonSet that scrapes control plane metrics. No component ever binds to 0.0.0.0.

First, disable the built-in scrapers in kube-prometheus-stack so nothing gets scraped twice. In its values.yaml:

kubeEtcd:
  enabled: false
kubeScheduler:
  enabled: false
kubeControllerManager:
  enabled: false
kubeProxy:
  enabled: false
prometheus:
  prometheusSpec:
    enableRemoteWriteReceiver: true

Clone the repository:

git clone https://github.com/adrghph/kps-zeroexposure.git
cd kps-zeroexposure

Point it at your central Prometheus instance by editing values.yaml. If that instance runs in the monitoring namespace, the URL looks like this:

remoteWriteUrl: http://kube-prometheus-stack-prometheus.monitoring.svc.cluster.local:9090/api/v1/write

Install the chart in the same namespace:

helm install kps-zeroexposure . -n monitoring

The DaemonSet runs an agent on every node. Each agent scrapes local control plane metrics such as etcd and the scheduler, then forwards them by remote write to the central Prometheus. Metrics endpoints stay off the network.

Why This Approach Is Secure

Unlike binding metrics endpoints to 0.0.0.0, kps-zeroexposure keeps endpoints on 127.0.0.1, limiting access to local processes. The Prometheus agent operates in a minimal mode without local storage or alert evaluation, reducing its attack surface. Metrics are pushed securely to the central Prometheus instance, which handles alerting and storage. This separation of concerns ensures that sensitive control plane metrics remain protected while enabling reliable monitoring.

Testing and Validation

After you deploy, check that metrics are being scraped.

First, look at the agent logs for errors:

kubectl logs -n monitoring -l app=kps-zeroexposure

Then check your central Prometheus instance. Its dashboards and alerts should show the scraped metrics.

Additional Considerations

Deploy kps-zeroexposure in the same namespace as kube-prometheus-stack (e.g., monitoring) so service discovery works. If some endpoints, such as kube-controller-manager or kube-scheduler, require HTTPS, configure TLS in the kps-zeroexposure values.yaml, or set insecure_skip_verify: true in environments where that is acceptable. Define alerts and dashboards in the central Prometheus instance, using labels like source or job for filtering, and validate everything in a non-production environment first.

Conclusion

The kps-zeroexposure solution resolves Prometheus scraping errors for Kubernetes control plane components without compromising security. By deploying a Prometheus Agent DaemonSet, it scrapes metrics locally and forwards them securely, avoiding the insecure practice of binding endpoints to 0.0.0.0. This approach, proposed in issue #5695, ensures robust monitoring with the kube-prometheus-stack Helm chart. For more details, refer to the kps-zeroexposure repository and the kube-prometheus-stack documentation.