cAdvisor (Container Advisor) – The Unsung Hero of Kubernetes Monitoring
Bavithran M
Senior Cloud & DevOps Engineer | AWS & Azure Certified | Kubernetes & Automation Advocate | Training | Mentoring | Uplifting Many IT Professionals
Kubernetes makes deploying and managing containers easier, but how do you monitor the CPU, memory, disk, and network usage of your running containers?
Meet cAdvisor (Container Advisor)—the built-in monitoring tool in Kubernetes that collects real-time resource usage metrics from running containers. It is lightweight, powerful, and essential for tracking container performance, optimizing workloads, and troubleshooting resource bottlenecks.
In this article, we will explore:
What is cAdvisor?
cAdvisor (Container Advisor) is an open-source monitoring tool developed by Google. It runs as part of the Kubelet on each Kubernetes node and is responsible for:
Key Features of cAdvisor:
? Per-container resource tracking – Monitors CPU, memory, network, and filesystem usage for each container.
? Historical performance insights – Maintains short-term history of resource consumption.
? Integrated with Kubernetes – Runs as part of Kubelet, requiring no separate setup.
? Exports data for external monitoring – Compatible with Prometheus, InfluxDB, and Google Cloud Monitoring.
Now, let’s explore two real-world scenarios where cAdvisor plays a crucial role.
Scenario 1: How cAdvisor Helps Optimize Container Resource Usage
(Monitoring and Managing Kubernetes Pod Resources)
Imagine you have a Node.js application running in Kubernetes. You define a pod with specific resource requests and limits:
apiVersion: v1
kind: Pod
metadata:
name: my-app
spec:
containers:
- name: node-app
image: node:18
resources:
requests:
cpu: "250m"
memory: "512Mi"
limits:
cpu: "500m"
memory: "1Gi"
Step 1: Kubernetes Schedules the Pod and cAdvisor Starts Monitoring
Step 2: Viewing cAdvisor Metrics for the Running Pod
You can access cAdvisor metrics via the Kubelet API:
kubectl proxy &
curl https://localhost:8001/api/v1/nodes/<node-name>/proxy/metrics/cadvisor
This provides real-time CPU, memory, and disk usage of the running container.
Step 3: Identifying Resource Bottlenecks
If your application starts slowing down or crashing, you can use cAdvisor to check:
Run the following command to check container memory usage:
kubectl top pod my-app --containers
Output:
领英推荐
CONTAINER CPU(cores) MEMORY(bytes)
node-app 400m 850Mi
Here, memory usage (850Mi) is exceeding the 1Gi limit, which may cause the pod to be evicted.
Step 4: Adjusting Resource Limits Based on cAdvisor Data
Based on cAdvisor insights, you can adjust resource requests/limits to prevent performance issues:
resources:
requests:
cpu: "500m"
memory: "1Gi"
limits:
cpu: "1"
memory: "2Gi"
This ensures better workload performance and prevents resource exhaustion.
Scenario 2: Detecting and Resolving High Disk and Network Utilization in Kubernetes
(Using cAdvisor to Troubleshoot Slow Applications and High Resource Consumption)
Imagine your backend service in Kubernetes is suddenly running slow. Users report high latency, but logs don’t show errors.
You suspect the issue could be high disk I/O or excessive network traffic. Let’s use cAdvisor to investigate.
Step 1: Checking Disk Utilization with cAdvisor
To monitor disk read/write operations per container, run:
kubectl proxy &
curl https://localhost:8001/api/v1/nodes/<node-name>/proxy/metrics/cadvisor | grep -i disk
If you see high disk read/write operations, it could mean:
Step 2: Monitoring Network Traffic with cAdvisor
If your application is slow, check network traffic stats:
kubectl proxy &
curl https://localhost:8001/api/v1/nodes/<node-name>/proxy/metrics/cadvisor | grep -i network
If a pod is using excessive network bandwidth, it could be:
Step 3: Taking Action Based on cAdvisor Data
Using cAdvisor for real-time insights helps you proactively detect performance issues before they affect users.
Key Takeaways
If you’re running Kubernetes clusters, understanding cAdvisor is crucial for optimizing workloads and troubleshooting performance issues.
Let’s Discuss
Do you use cAdvisor for monitoring in Kubernetes? How do you handle container resource issues? Share your insights in the comments.
Follow Bavithran M for more DevOps, Kubernetes, and cloud-native insights.
Found this useful? Share it with your network
?? Cloud DevOps | ?? Azure | ??? Terraform | ?? Docker | ?? Kubernetes | ?? Infrastructure Automation Enthusiast | ?? Driving Scalability & Innovation
4 周Very helpful