Want to monitor your Kubernetes cluster easily? Prometheus is your go-to tool. It helps you track cluster health, detect issues early, and optimize resource usage. Here’s what you’ll get:
- Why monitor Kubernetes? Real-time insights, early issue detection, and efficient resource management.
- What is Prometheus? A powerful, open-source tool designed for dynamic container environments with features like PromQL and built-in reliability.
- Quick setup guide: Use Helm to install Prometheus and related tools like Grafana and Alertmanager.
- Key metrics to track: Node, pod, container, cluster, and network performance.
- Advanced tips: Create custom metrics, optimize configurations, and set up actionable alerts.
Start monitoring your Kubernetes cluster in minutes using this guide. Let’s dive in!
Before You Start
Cluster Setup Requirements
Your Kubernetes cluster must meet specific resource needs:
| Component | CPU (cores) | RAM (GiB) | Storage (GiB) |
|---|---|---|---|
| Prometheus | 0.5 | 1.0 | 20-60 |
| Grafana | 1.0 | 0.2 | 10 |
| Alertmanager | 0.5 | 0.05 | N/A |
Make sure your cluster has persistent storage to retain monitoring data even after restarts. Storage requirements depend on factors like metric collection frequency, the number of monitored targets, data retention duration, and metric cardinality. Once you’ve confirmed these, move on to ensuring your system has the necessary tools.
Required Tools
To set up Prometheus monitoring, you’ll need the following:
- A functional Kubernetes cluster with admin access
- The kubectl CLI tool, configured to communicate with your cluster
- git for downloading configuration files
- Permissions to create roles and bindings at the cluster level
If you’re using GKE, ensure you have additional cluster role permissions. With these tools and permissions ready, the next step is understanding the components of Prometheus.
Prometheus Components

Prometheus consists of several key components:
1. Core Components
The Prometheus server is the backbone, responsible for collecting and storing metrics. Its pull-based architecture is well-suited for containerized environments, offering reliability and scalability.
2. Data Collection Tools
- Node Exporter: Gathers metrics about the host system.
- Kube-state-metrics: Provides information about the cluster’s orchestration state.
- Target Auto-discovery: Automatically identifies and monitors targets.
3. Supporting Services
- Alertmanager: Manages notifications and alerts.
- Grafana: Creates visual dashboards using the collected metrics.
"Monitoring Kubernetes using Prometheus can be a complex undertaking. It is crucial to adopt configuration best practices that ensure core Kubernetes components expose metrics securely. Prometheus can then scrape them in real time for rapid analysis and visualization." – Squadcast Community [1]
To ensure everything runs smoothly, follow these best practices:
- Set resource requests and limits based on your workload’s needs.
- Use network policies to restrict unauthorized access.
- Create and use dedicated service accounts.
- Store configuration details in ConfigMaps for better management.
Installing Prometheus
Helm Installation Steps

Follow these steps to set up Prometheus using Helm:
- Create a namespace for monitoring:
kubectl create namespace monitoring - Add the Prometheus community repository to Helm and update it:
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts helm repo update - Install Prometheus using the Helm chart:
helm install prometheus prometheus-community/kube-prometheus-stack --namespace monitoring
Basic Configuration
The default settings work for most setups, but you can adjust key configurations based on your needs:
| Configuration Area | Key Settings | Suggested Values |
|---|---|---|
| Resource Limits | CPU/Memory | 2 CPU cores, 4 GiB RAM |
| Storage | Retention | 15 days, 50 GiB |
| Scrape Interval | Metrics Collection | 30 seconds |
To apply custom configurations, update your values.yaml file and run:
helm upgrade prometheus prometheus-community/kube-prometheus-stack -f values.yaml --namespace monitoring
Testing Your Installation
Check if Prometheus is running by verifying the pod status:
kubectl get pods -n monitoring
You should see pods like these:
-
prometheus-prometheus-0 -
prometheus-alertmanager-0 -
prometheus-node-exporter
To access the Prometheus dashboard locally, set up port forwarding:
kubectl port-forward -n monitoring svc/prometheus-operated 9090:9090
For example, in March 2024, a company successfully deployed Prometheus using Helm charts. They tailored their setup by modifying the prometheus.yml file to monitor Docker containers outside their Kubernetes cluster, ensuring comprehensive metrics collection [2].
Manage Prometheus configurations separately with ConfigMaps. Once installed and verified, you can move on to setting up monitoring.
Setting Up Monitoring
Collecting Kubernetes Metrics

Once Prometheus is installed, configure it to gather key Kubernetes metrics. Prometheus uses an HTTP pull model, which is efficient for handling large-scale deployments.
Here’s a breakdown of essential metric types:
| Metric Type | Description | Key Indicators |
|---|---|---|
| Node Metrics | Resource usage per node | CPU, memory, disk utilization |
| Pod Metrics | Individual pod performance | Resource consumption, status |
| Container Metrics | Container-level insights | CPU/memory usage per container |
| Cluster Metrics | Overall cluster health | Running pods, node availability |
| Network Metrics | Communication patterns | Transfer rates, error counts |
For example, to monitor CPU usage by node, use this PromQL query:
sum(rate(node_cpu_seconds_total{mode!="idle"}[5m])) by (instance)
Once metrics collection is set up, the next step is to define which services Prometheus should monitor.
Adding Service Monitors
Service Monitors are custom resources that guide Prometheus on which services to observe and how to gather their metrics. Follow these steps to monitor specific services:
- Annotate the service for Prometheus monitoring:
metadata: annotations: prometheus.io/scrape: "true" prometheus.io/port: "metrics"
- Create a ServiceMonitor configuration:
apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: name: app-monitor namespace: monitoring spec: endpoints: - interval: 15s port: metrics selector: matchLabels: app.kubernetes.io/name: your-app
This setup tells Prometheus to scrape metrics from the specified service at regular intervals.
Creating Custom Metrics
Custom metrics help you gain detailed insights into your application’s performance. Using the Prometheus Golang Client API, you can define transaction counters, active client gauges, and response time histograms to track performance comprehensively [4].
"Kubernetes solves the application availability management problem through the liveness and readiness probes. Now, how about application performance? Prometheus gives us the capability to instrument the application with the Client API. We can use the API to define the custom metrics to monitor the performance of the application." [4]
To implement custom metrics:
- Use a Prometheus client library compatible with your application’s programming language.
- Define metrics that align with your monitoring goals.
- Expose these metrics on an HTTP endpoint, typically
/metrics. - Create a ServiceMonitor to scrape the custom metrics.
For tracking memory usage by pod, this PromQL query is useful:
sum(container_memory_usage_bytes{container!="POD",pod!=""}) by (pod)
sbb-itb-5c61b71
Setup Prometheus Monitoring on Kubernetes using Helm and …
Using Prometheus Data
With Prometheus gathering your metrics, you can analyze and visualize data effectively to understand your Kubernetes cluster’s performance.
Using the Prometheus Dashboard
You can access Kubernetes metrics through PromQL queries on the Prometheus dashboard at http://your-prometheus-server:9090.
The dashboard has three main sections:
| Section | Purpose | Key Features |
|---|---|---|
| Graph | Analyze metrics visually | Time-series plots and range selection |
| Console | View raw data | Tabular format and instant queries |
| Alerts | Manage alerts | Monitor alert rules and statuses |
Here are some example PromQL queries to get started:
- Count pods per namespace:
sum by (namespace) (kube_pod_info) - Check pod restarts over a 5-minute period:
sum by (namespace)(changes(kube_pod_status_ready{condition="true"}[5m]))
Once you’ve explored the dashboard, focus on monitoring key metrics to maintain cluster health.
Important Metrics to Track
Keep an eye on these metrics to ensure your cluster runs smoothly:
- Resource Utilization: Track CPU and memory usage. Aim for usage between 60–80% of requests to avoid over- or under-utilization. Monitor resource limits and actual usage regularly.
- Cluster Health: Check metrics like pod availability, node status, and Persistent Volume usage to identify any issues promptly.
For more advanced visualizations, integrate Prometheus with Grafana.
Creating Grafana Visualizations

Add Prometheus as a data source in Grafana, then import ready-made dashboards (e.g., ID 3119 for cluster monitoring or ID 6417 for node statistics).
You can also create custom visualizations with these PromQL queries:
- Resource Distribution Across Pods:
sum(rate(container_resource_usage_seconds_total[5m])) by (pod) - Network Performance by Pod:
sum(rate(container_network_receive_bytes_total[5m])) by (pod)
Set up Grafana dashboards to display trends in resource usage, pod status, node health, and network performance. Combining Prometheus for data collection with Grafana for visualization gives you a detailed view of your Kubernetes cluster’s health and performance [3].
Performance Tuning
After setting up Prometheus, it’s important to optimize its performance for smooth cluster operations. Below are some key adjustments you can make.
Adjusting Data Collection
You can refine data collection by focusing on these areas:
| Optimization Area | Action | Impact |
|---|---|---|
| Metric Selection | Use relabeling to drop unused metrics | Reduces resource consumption |
| Collector Config | Turn off unnecessary node_exporter collectors |
Lowers data volume |
| Scrape Intervals | Adjust intervals based on metric importance | Balances data resolution and load |
David Calvert, a Staff Site Reliability Engineer, achieved impressive results by tuning these parameters – CPU usage dropped by 119%, and memory consumption decreased by 139%.
"In order to improve the performance of your Prometheus setup, you will need to understand your usage and make the right design choice depending on your use-case and scale." [5]
Once you’ve optimized data collection, it’s time to set up alerts to handle performance issues effectively.
Setting Up Alerts
Design alerts to address persistent issues instead of reacting to brief spikes. Here’s an example of a CPU utilization alert:
groups: - name: example_alerts rules: - alert: HighCPUUtilization expr: avg(node_cpu{mode="system"}) > 80 for: 5m labels: severity: critical annotations: summary: High CPU utilization on host {{ $labels.instance }} description: The CPU utilization has exceeded 80% for 5 minutes
Make sure your alerts are:
- Actionable: Include clear steps for resolving the issue.
- Context-rich: Provide detailed system information.
- Tiered: Route notifications based on the severity level.
- Integrated: Connect with your incident management tools.
After setting up alerts, focus on optimizing Prometheus for larger, high-traffic clusters.
Managing Large Clusters
For large-scale environments, consider these strategies:
- Focus on high-cardinality metrics, especially those with many unique label combinations.
- Use
pprofto analyze CPU and memory usage. - Implement RBAC to manage resources effectively.
To identify resource-heavy metrics, use the Cardinality Explorer dashboard (Grafana ID 11304). This tool pinpoints areas that need immediate attention, helping you maintain peak performance.
Next Steps
With your Prometheus setup running smoothly, it’s time to enhance your monitoring by adding advanced tools and strategies. For instance, integrating Grafana can provide more detailed and interactive visualizations.
Make sure to deploy key components like Kube-state-metrics, Node-Exporter, and Alertmanager to take your monitoring capabilities to the next level.
For handling larger deployments, consider these scaling methods:
| Scaling Approach | When to Use | Benefit |
|---|---|---|
| Functional Sharding | Monitoring multiple clusters or regions | Balances the monitoring load |
| Federation | When hierarchical monitoring is needed | Allows metrics aggregation |
| Thanos | If a global view and durable storage are required | Ensures long-term storage |
To keep your monitoring effective, regularly review your objectives and update your configurations. Using the Prometheus Operator can simplify the management and scaling of your setup, making it easier to maintain over time [6].
