In this lesson, you will learn how cAdvisor provides deep, container-level visibility by acting as the foundational engine for gathering performance metrics in your Kubernetes clusters.
Understanding cAdvisor
While the Node Exporter gives you a bird’s-eye view of your server's health, it doesn't "see" inside individual containers. cAdvisor (Container Advisor) is an open-source tool built directly into the kubelet binary that specifically inspects, analyzes, and exports resource usage statistics for every container running on a node.
Instead of needing a separate agent for every container, cAdvisor automatically discovers all containers managed by the container runtime (like containerd or CRI-O). It collects fine-grained telemetry data, including:
- CPU: Usage per core, throttling events, and total time spent.
- Memory: Working set size, cache, and page faults.
- Network: Bytes received and transmitted, along with error rates per interface.
How It Works
Because cAdvisor is embedded in the kubelet, it exposes these metrics on a local port (typically 10250 or 10255). When you set up Prometheus to monitor your cluster, you configure it to scrape these endpoints. Prometheus then gathers this granular data, allowing you to build dashboards or alerts for specific pods.
For example, if a specific microservice is experiencing a memory leak, cAdvisor provides the metrics to pinpoint that exact container rather than just showing that the host is running out of RAM.
You don't need to install anything extra; cAdvisor is already running. You simply need to ensure your Prometheus configuration targets the kubelet metrics service to start collecting the data:
# Example snippet for a Prometheus scrape job targeting cAdvisor
- job_name: 'kubernetes-cadvisor'
scheme: https
tls_config:
ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
kubernetes_sd_configs:
- role: node
relabel_configs:
- action: labelmap
regex: __meta_kubernetes_node_label_(.+)
- target_label: __address__
replacement: kubernetes.default.svc:443
- source_labels: [__meta_kubernetes_node_name]
regex: (.+)
target_label: __metrics_path__
replacement: /api/v1/nodes/${1}/proxy/metrics/cadvisor
By leveraging this built-in engine, you gain the precise observability necessary to right-size your resource requests and troubleshoot performance bottlenecks effectively.
Key Takeaway: cAdvisor is the internal powerhouse that allows the kubelet to expose container-specific resource metrics, providing the visibility needed for precise performance monitoring and capacity planning.