
Integrating Prometheus with Kubernetes
Read more about this topic
Unlock real-time visibility into your Kubernetes clusters by mastering Prometheus integration—the industry-standard for cloud-native monitoring. This guide walks you through scraping metrics from pods, nodes, and services, setting up service monitors, and querying with PromQL to detect anomalies before they impact users. Learn to combine Prometheus with Grafana dashboards, alerting rules, and auto-discovery for dynamic environments, ensuring your DevOps pipelines stay resilient. Perfect for developers and SREs seeking hands-on strategies to optimize performance, reduce downtime, and scale observability effortlessly. Get ready to turn raw telemetry into actionable insights and elevate your Kubernetes operations to the next level.
Articles in Integrating Prometheus with Kubernetes
Don't Fly Blind: Prometheus as Your Kubernetes Copilot
Prometheus & Kubernetes: A Match Made in Monitoring Heaven?
Prometheus: Your AllSeeing Eye on Kubernetes Operations
Integrating Prometheus with Kubernetes: Unlock Deep Cluster Visibility
Welcome to LearnDevOpsFast’s deep dive on integrating Prometheus with Kubernetes. This powerful combination gives you time-series metrics, real-time alerting, and a scalable monitoring backbone for your containerized workloads. Below, we break down the essential steps, components, and best practices to transform your Kubernetes clusters from black boxes into transparent, self-healing systems. Expect actionable advice, production-ready patterns, and clear explanations designed to accelerate your DevOps journey.
🔧 Core Architecture: Prometheus Operator vs Manual Deployment
Choosing the right deployment method is your first critical decision. The Prometheus Operator is the modern, declarative approach that uses Kubernetes custom resources (ServiceMonitors, PodMonitors, AlertmanagerConfig) to automate configuration and service discovery. It reduces human error and scales with your cluster. Alternatively, manual deployment gives you fine-grained control but requires handcrafted configmaps and persistent care for tags, relabeling, and target discovery.
For most teams, we recommend the Operator because it aligns with GitOps workflows, supports automatic scraping of new pods, and simplifies lifecycle management. You’ll get a kube-prometheus-stack (Helm chart) that bundles Prometheus, Alertmanager, Grafana, and node exporters out of the box. This stack provides a production-ready baseline, letting you focus on metric selection rather than wiring glue code. Manual setups are best only for edge cases where you need custom exporters outside Operator patterns.
📡 Service Discovery and Scraping Configuration Essentials
Once Prometheus is running, the magic happens via service discovery. Kubernetes’ native support lets Prometheus automatically find pods, services, and endpoints based on labels and annotations. You define a ServiceMonitor that targets services with a specific label like app: my-app, and Prometheus scrapes their /metrics endpoint. This eliminates static target lists and adapts as pods scale up or down.
Key to success is mastering relabeling rules. Use __meta_kubernetes_* labels to enrich metrics with namespace, pod name, or container image. For example, you can drop metrics from sidecars or add job labels for cleaner queries. Also, set sensible scrape intervals (15–30s) and timeouts to avoid overloading your etcd. Test with scrape_configs only after verifying your ServiceMonitor selectors, as a misconfigured label silently produces empty targets.
📊 Metrics Collection: kube-state-metrics and Node Exporters
Out-of-the-box Prometheus can’t understand Kubernetes internals like deployment replicas or pod statuses. That’s where kube-state-metrics steps in. It listens to the Kubernetes API and exposes metrics such as kube_deployment_status_replicas, kube_pod_container_status_restarts, and kube_node_status_condition. Install it via the same Helm chart to get a rich dataset without writing custom code.
For infrastructure-level metrics (CPU, memory, disk, network), deploy node exporters as a DaemonSet. These run on every node and feed node_cpu_seconds_total or node_filesystem_avail_bytes. Combine these with Kubernetes namespace annotations to build dashboards that show per-pod resource usage against node capacity. Also, consider kubelet’s cAdvisor metrics (under /metrics/cadvisor) for container-level CPU and memory, which is essential for right-sizing your requests and limits.
🚨 Alerting with Alertmanager: From Silence to Action
Collecting metrics without alerting is like having a smoke detector with no alarm. Alertmanager handles deduplication, grouping, and routing of alerts to channels like Slack, email, or PagerDuty. For Kubernetes, define PrometheusRule objects that contain alert expressions. Classic rules include KubePodCrashLooping, KubeDeploymentReplicasMismatch, and KubeNodeNotReady. Group alerts by namespace to avoid notification storms.
You’ll also manage inhibition rules to suppress lower-severity alerts when a major incident like NodeDown occurs. Set up route trees to send critical alerts to on-call, while warnings go to a team channel. Use templates to include pod logs or a Grafana link. Test your alert flow with amtool or the Alertmanager UI before relying on it in production. Remember: a well-tuned alert fires only when action is needed, reducing fatigue.
📈 Visualization and Grafana Dashboards for Kubernetes
Raw PromQL is powerful but hard to read at 3 AM. Grafana turns your metrics into visual stories with pre-built dashboards like Kubernetes Cluster, Pods, and Nodes. Import the official dashboards from Grafana.com (IDs 315, 641, etc.) to instantly see CPU, memory, network, and disk for your entire fleet. Then customize panels to show top-n pods by CPU or error rates from HTTP metrics.
For long-term retention, configure Prometheus’s remote write to Thanos or Mimir, but for most single-cluster needs, local storage with 15-day retention suffices. Use Grafana annotations to mark deployments or rollbacks. Set up variable-based dashboards (e.g., namespace picker) to drill down without rewriting queries. Finally, enable alerting in Grafana as a secondary path, but prefer Alertmanager for alert management to avoid duplication.
Frequently Asked Questions
How do I expose Prometheus to external access securely?
Use an Ingress with TLS termination and basic auth or OAuth2 proxy. Alternatively, keep Prometheus internal and access dashboards via kubectl port-forward for debugging. For production, integrate with OIDC or use a service mesh like Istio for mTLS. Never expose the Prometheus UI publicly without authentication.
What is the difference between kube-state-metrics and cAdvisor metrics?
kube-state-metrics provides high-level Kubernetes object states (e.g., deployment replicas, pod status) via the API server, while cAdvisor (part of kubelet) gives low-level container resource usage (CPU, memory) from the runtime. Use both together for complete visibility: kube-state for orchestration health, cAdvisor for resource utilization.
Can I monitor multiple Kubernetes clusters with one Prometheus?
Yes, but it’s complex. Use federated Prometheus with a global set for cross-cluster queries, or better, implement Thanos or Cortex for multi-cluster aggregation. For simplicity, run a dedicated Prometheus per cluster and federate only essential metrics to a central instance.
How do I handle high cardinality metrics in Kubernetes?
High cardinality usually comes from labels like pod names or request paths. Trim labels using relabeling, aggregate with PromQL (e.g., sum by (namespace)), or use recording rules. Monitor TSDB size and use sample limits per target. Also, avoid exporting metrics with unbounded unique values like timestamps or trace IDs.
Why do my alerts not fire despite having PrometheusRule resources?
Check that the rule selector in your Prometheus CR matches the ruleSelector labels. Verify the rule’s PromQL expression returns a vector for evaluation—use empty brackets for instant queries. Also ensure Alertmanager’s route matches the alert name and that your alertmanagerConfig is loaded. Test with a dummy alert to confirm pipeline.

