๐Part 4 Optimize Kubernetes Monitoring: A Complete Guide to Prometheus and Grafana Integration


๐ Advanced Kubernetes Monitoring with Prometheus, Grafana, Node Exporter & cAdvisor
1๏ธโฃ Overview
Monitoring Kubernetes effectively requires collecting metrics from both the cluster and individual nodes. This guide extends our monitoring setup by adding:
โ
Prometheus โ Collects Kubernetes cluster metrics
โ
Grafana โ Visualizes metrics in dashboards
โ
Node Exporter โ Captures node-level CPU, memory, and disk metrics
โ
cAdvisor โ Monitors container-level resource usage
By the end of this guide, you'll have deep visibility into your Kubernetes environment. ๐
2๏ธโฃ Deploying Prometheus
๐ Ensure you have created a monitoring namespace:
kubectl create namespace monitoring
โ Sample Output:
namespace/monitoring created
๐น Apply Prometheus Configurations
curl -o prometheus-config.yaml https://raw.githubusercontent.com/Vikas-DevOpsPractice/EasyShop/feature/kindcluster/K8s/14-prometheus-config.yaml
curl -o prometheus-deployment.yaml https://raw.githubusercontent.com/Vikas-DevOpsPractice/EasyShop/feature/kindcluster/K8s/15-prometheus-deployment.yaml
kubectl apply -f prometheus-config.yaml -n monitoring
kubectl apply -f prometheus-deployment.yaml -n monitoring
โ Check Prometheus Deployment:
kubectl get pods -n monitoring
โ Sample Output:
NAME READY STATUS RESTARTS AGE
prometheus-5f9d77c86f-xyz12 1/1 Running 0 1m
3๏ธโฃ Deploying Node Exporter
๐น Why Node Exporter?
๐น Collects CPU, Memory, Disk, and Network usage of each Kubernetes node
๐น Provides hardware and OS metrics
๐น Step 1: Create a DaemonSet for Node Exporter
# node-exporter-daemonset.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: node-exporter
namespace: monitoring
spec:
selector:
matchLabels:
app: node-exporter
template:
metadata:
labels:
app: node-exporter
spec:
hostNetwork: true
containers:
- name: node-exporter
image: prom/node-exporter:v1.5.0
ports:
- containerPort: 9100
hostPort: 9100
โ Apply the DaemonSet:
kubectl apply -f node-exporter-daemonset.yaml -n monitoring
โ Verify Deployment:
kubectl get pods -n monitoring
โ Sample Output:
NAME READY STATUS RESTARTS AGE
node-exporter-xyz12 1/1 Running 0 1m
4๏ธโฃ Deploying cAdvisor
๐น Why cAdvisor?
๐น Provides per-container resource usage (CPU, memory, disk, network)
๐น Helps in troubleshooting slow or resource-hungry containers
๐น Step 1: Create a DaemonSet for cAdvisor
# cadvisor-daemonset.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: cadvisor
namespace: monitoring
spec:
selector:
matchLabels:
app: cadvisor
template:
metadata:
labels:
app: cadvisor
spec:
hostNetwork: true
containers:
- name: cadvisor
image: gcr.io/cadvisor/cadvisor:v0.47.0
ports:
- containerPort: 8080
hostPort: 8080
โ Apply the DaemonSet:
kubectl apply -f cadvisor-daemonset.yaml -n monitoring
โ Verify Deployment:
kubectl get pods -n monitoring
โ Sample Output:
NAME READY STATUS RESTARTS AGE
cadvisor-xyz12 1/1 Running 0 1m
5๏ธโฃ Integrating Node Exporter & cAdvisor with Prometheus
๐น Update Prometheus Configuration
Add the following scrape jobs to prometheus-config.yaml:
scrape_configs:
- job_name: 'node-exporter'
static_configs:
- targets: ['node-exporter.monitoring.svc.cluster.local:9100']
- job_name: 'cadvisor'
static_configs:
- targets: ['cadvisor.monitoring.svc.cluster.local:8080']
โ Reapply Prometheus Configuration:
kubectl apply -f prometheus-config.yaml -n monitoring
kubectl rollout restart deployment prometheus -n monitoring
6๏ธโฃ Deploying Grafana
curl -o grafana-deployment.yaml https://raw.githubusercontent.com/Vikas-DevOpsPractice/EasyShop/feature/kindcluster/K8s/16-grafana-deployment.yaml
kubectl apply -f grafana-deployment.yaml -n monitoring
โ Verify Grafana:
kubectl get pods -n monitoring
โ Sample Output:
NAME READY STATUS RESTARTS AGE
grafana-78b6c9c76f-xyz12 1/1 Running 0 1m
7๏ธโฃ Setting Up Dashboards in Grafana
๐น Add Prometheus as a Data Source
๐ Go to Grafana โ Configuration โ Add Data Source
๐น Select Prometheus
๐น Set URL to:
http://prometheus.monitoring.svc.cluster.local:9090
๐น Click Save & Test
โ Integration Successful!
๐น Import Prebuilt Kubernetes Dashboards
๐ Go to Grafana Dashboard โ Click Dashboards โ Import
๐น Use Dashboard ID: 11074 (Node Exporter)
๐น Use Dashboard ID: 13689 (cAdvisor)
๐น Select Prometheus as the data source โ Click Import
โ Sample Node Metrics Dashboard:
โ Sample Container Metrics Dashboard:
8๏ธโฃ Setting Up Alerts in Grafana
๐ Open Grafana โ Click Alerts โ Create Alert Rule
๐น Condition: Alert when CPU Usage > 80% for 5 minutes
๐น Notification: Email, Slack, PagerDuty
๐น Click Save & Enable Alerting
โ Now, alerts will trigger on resource spikes!
9๏ธโฃ Troubleshooting & Best Practices
๐น Prometheus Not Collecting Metrics?
kubectl logs -l app=prometheus -n monitoring
๐ Ensure the scrape configs in prometheus-config.yaml
are correct
๐น Node Exporter Not Running?
kubectl describe pod node-exporter-xyz12 -n monitoring
๐ Ensure hostPort 9100 is available
๐น cAdvisor Metrics Not Appearing?
kubectl logs -l app=cadvisor -n monitoring
๐ Ensure cadvisor.monitoring.svc.cluster.local:8080
is correct in Prometheus config
๐ฏ Conclusion
๐ Advanced Kubernetes Monitoring is now fully set up!
โ
Prometheus collects Kubernetes & node metrics
โ
Node Exporter tracks hardware performance
โ
cAdvisor monitors per-container usage
โ
Grafana visualizes & alerts on key metrics
Subscribe to my newsletter
Read articles from Vikas Surve directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Vikas Surve
Vikas Surve
I am an ๐ ๐ฆ ๐๐ฒ๐ฟ๐๐ถ๐ณ๐ถ๐ฒ๐ฑ ๐๐ฒ๐๐ข๐ฝ๐ ๐๐ป๐ด๐ถ๐ป๐ฒ๐ฒ๐ฟ ๐๐ ๐ฝ๐ฒ๐ฟ๐ and ๐๐๐๐ฟ๐ฒ ๐๐ฑ๐บ๐ถ๐ป๐ถ๐๐๐ฟ๐ฎ๐๐ผ๐ฟ ๐๐๐๐ผ๐ฐ๐ถ๐ฎ๐๐ฒ with over ๐ญ๐ฌ ๐๐ฒ๐ฎ๐ฟ๐ ๐ผ๐ณ ๐ฒ๐ ๐ฝ๐ฒ๐ฟ๐ถ๐ฒ๐ป๐ฐ๐ฒ in designing, implementing, and optimizing DevOps solutions. My expertise includes ๐๐/๐๐ ๐ฎ๐๐๐ผ๐บ๐ฎ๐๐ถ๐ผ๐ป ๐๐๐ถ๐ป๐ด ๐๐ถ๐๐๐ฎ๐ฏ, ๐๐ฒ๐ป๐ธ๐ถ๐ป๐, ๐ฎ๐ป๐ฑ ๐๐๐๐ฟ๐ฒ ๐๐ฒ๐๐ข๐ฝ๐, as well as ๐๐ผ๐ป๐๐ฎ๐ถ๐ป๐ฒ๐ฟ ๐ผ๐ฟ๐ฐ๐ต๐ฒ๐๐๐ฟ๐ฎ๐๐ถ๐ผ๐ป ๐๐ถ๐๐ต ๐๐ผ๐ฐ๐ธ๐ฒ๐ฟ ๐ฎ๐ป๐ฑ ๐๐๐ฏ๐ฒ๐ฟ๐ป๐ฒ๐๐ฒ๐. ๐น ๐๐ ๐ฝ๐ฒ๐ฟ๐ ๐ถ๐ป ๐ฑ๐ฒ๐๐ถ๐ด๐ป๐ถ๐ป๐ด ๐ฎ๐ป๐ฑ ๐บ๐ฎ๐ป๐ฎ๐ด๐ถ๐ป๐ด ๐ฒ๐ป๐ฑ-๐๐ผ-๐ฒ๐ป๐ฑ ๐๐/๐๐ ๐ฝ๐ถ๐ฝ๐ฒ๐น๐ถ๐ป๐ฒ๐ ๐น ๐๐ฎ๐ป๐ฑ๐-๐ผ๐ป ๐ฒ๐ ๐ฝ๐ฒ๐ฟ๐ถ๐ฒ๐ป๐ฐ๐ฒ ๐๐ถ๐๐ต ๐๐๐๐ฟ๐ฒ, ๐๐๐ฏ๐ฒ๐ฟ๐ป๐ฒ๐๐ฒ๐ (๐๐๐ฆ), ๐ฎ๐ป๐ฑ ๐ง๐ฒ๐ฟ๐ฟ๐ฎ๐ณ๐ผ๐ฟ๐บ ๐ณ๐ผ๐ฟ ๐๐ฐ๐ฎ๐น๐ฎ๐ฏ๐น๐ฒ ๐ฑ๐ฒ๐ฝ๐น๐ผ๐๐บ๐ฒ๐ป๐๐ ๐น ๐ฃ๐ฎ๐๐๐ถ๐ผ๐ป๐ฎ๐๐ฒ ๐ฎ๐ฏ๐ผ๐๐ ๐ฎ๐๐๐ผ๐บ๐ฎ๐๐ถ๐ผ๐ป, ๐๐ฒ๐ฐ๐๐ฟ๐ถ๐๐, ๐ฎ๐ป๐ฑ ๐ฐ๐น๐ผ๐๐ฑ-๐ป๐ฎ๐๐ถ๐๐ฒ ๐๐ฒ๐ฐ๐ต๐ป๐ผ๐น๐ผ๐ด๐ถ๐ฒ๐ ๐ ๐ฆ๐ธ๐ถ๐น๐น๐ & ๐ง๐ผ๐ผ๐น๐ โ ๐๐ฒ๐๐ข๐ฝ๐ & ๐๐/๐๐: Azure DevOps, GitLab, Jenkins โ ๐๐น๐ผ๐๐ฑ & ๐๐ป๐ณ๐ฟ๐ฎ๐๐๐ฟ๐๐ฐ๐๐๐ฟ๐ฒ: Azure, AWS โ ๐๐ป๐ณ๐ฟ๐ฎ๐๐๐ฟ๐๐ฐ๐๐๐ฟ๐ฒ ๐ฎ๐ ๐๐ผ๐ฑ๐ฒ (๐๐ฎ๐): Terraform, Bicep โ ๐๐ผ๐ป๐๐ฎ๐ถ๐ป๐ฒ๐ฟ๐ & ๐ข๐ฟ๐ฐ๐ต๐ฒ๐๐๐ฟ๐ฎ๐๐ถ๐ผ๐ป: Docker, Kubernetes (AKS) โ ๐๐ผ๐ป๐ณ๐ถ๐ด ๐ ๐ฎ๐ป๐ฎ๐ด๐ฒ๐บ๐ฒ๐ป๐: PowerShell, Shell Scripting โ ๐ ๐ผ๐ป๐ถ๐๐ผ๐ฟ๐ถ๐ป๐ด & ๐ข๐ฏ๐๐ฒ๐ฟ๐๐ฎ๐ฏ๐ถ๐น๐ถ๐๐: Grafana, Prometheus, Azure Monitor โ ๐ฆ๐ฒ๐ฐ๐๐ฟ๐ถ๐๐ & ๐ก๐ฒ๐๐๐ผ๐ฟ๐ธ๐ถ๐ป๐ด: Load Balancers, Firewalls, ClusterIP โ ๐ข๐ฝ๐ฒ๐ฟ๐ฎ๐๐ถ๐ป๐ด ๐ฆ๐๐๐๐ฒ๐บ๐: Linux, Mac ๐ก ๐๐ฒ๐ ๐ฆ๐๐ฟ๐ฒ๐ป๐ด๐๐ต๐ โ ๐๐น๐ผ๐๐ฑ ๐๐ฟ๐ฐ๐ต๐ถ๐๐ฒ๐ฐ๐๐๐ฟ๐ฒ & ๐๐๐๐ผ๐บ๐ฎ๐๐ถ๐ผ๐ป โ Designing and managing scalable cloud solutions โ ๐๐/๐๐ & ๐๐ฒ๐๐ข๐ฝ๐ ๐๐ฒ๐ฎ๐ฑ๐ฒ๐ฟ๐๐ต๐ถ๐ฝ โ Implementing robust and automated software delivery pipelines โ ๐ง๐ฒ๐ฎ๐บ ๐๐ฒ๐ฎ๐ฑ๐ฒ๐ฟ๐๐ต๐ถ๐ฝ & ๐ ๐ฒ๐ป๐๐ผ๐ฟ๐๐ต๐ถ๐ฝ โ Leading a 5-member team, fostering collaboration and growth โ ๐ฆ๐ฒ๐ฐ๐๐ฟ๐ถ๐๐ & ๐๐ผ๐บ๐ฝ๐น๐ถ๐ฎ๐ป๐ฐ๐ฒ โ Ensuring cloud security, compliance, and best practices โ ๐ฃ๐ฟ๐ผ๐ฏ๐น๐ฒ๐บ ๐ฆ๐ผ๐น๐๐ถ๐ป๐ด & ๐ข๐ฝ๐๐ถ๐บ๐ถ๐๐ฎ๐๐ถ๐ผ๐ป โ Driving efficiency through automation and DevOps practices โ ๐๐ผ๐ป๐๐ถ๐ป๐๐ผ๐๐ ๐๐ฒ๐ฎ๐ฟ๐ป๐ถ๐ป๐ด & ๐๐ป๐ป๐ผ๐๐ฎ๐๐ถ๐ผ๐ป โ Exploring emerging technologies and best practices