Skip to content

cAdvisor (container Advisor)

cAdvisor (container Advisor) is a tool used to monitor resource usage information within containers^[400-devops__06-Kubernetes__k8s-paas__07.Promtheus监控k8s企业级应用.md].

Overview

cAdvisor provides visibility into the performance and resource consumption of running containers. It is a core component in Prometheus monitoring architectures, specifically for gathering container-level metrics^[400-devops__06-Kubernetes__k8s-paas__07.Promtheus监控k8s企业级应用.md].

In a Kubernetes environment, cAdvisor is typically deployed as a [[DaemonSet]] to ensure that it runs on every node in the cluster^[400-devops__06-Kubernetes__k8s-paas__07.Promtheus监控k8s企业级应用.md].

Key Implementation Details

Deployment Strategy

The standard deployment method involves creating a DaemonSet so that a cAdvisor Pod runs on every cluster node^[400-devops__06-Kubernetes__k8s-paas__07.Promtheus监控k8s企业级应用.md]. This ensures comprehensive coverage of all containerized workloads across the infrastructure.

Network Configuration

In standard configurations, cAdvisor utilizes the hostNetwork of the node^[400-devops__06-Kubernetes__k8s-paas__07.Promtheus监控k8s企业级应用.md]. By default, it exposes its Metrics on port 4194^[400-devops__06-Kubernetes__k8s-paas__07.Promtheus监控k8s企业级应用.md].

Volume Mounts

To function correctly, cAdvisor requires specific host paths to be mounted into the container. These typically include: * Root filesystem (/ or /rootfs): Mounted as read-only to monitor overall disk usage^[400-devops__06-Kubernetes__k8s-paas__07.Promtheus监控k8s企业级应用.md]. * Docker Data (/var/lib/docker): Mounted as read-only to access Docker container statistics^[400-devops__06-Kubernetes__k8s-paas__07.Promtheus监控k8s企业级应用.md]. * System Volumes (/sys): Mounted as read-only for hardware and kernel event information^[400-devops__06-Kubernetes__k8s-paas__07.Promtheus监控k8s企业级应用.md]. * Runtime Data (/var/run): Mounted to communicate with the container runtime^[400-devops__06-Kubernetes__k8s-paas__07.Promtheus监控k8s企业级应用.md].

Prometheus Integration

cAdvisor acts as an Exporter for Prometheus[^[400-devops__06-Kubernetes__k8s-paas__07.Promtheus监控k8s企业级应用.md]]. The Prometheus server is configured to scrape Metrics from the cAdvisor targets discovered via Kubernetes Service Discovery.

Example Prometheus scrape configuration for cAdvisor:

- job_name: 'kubernetes-cadvisor'
  kubernetes_sd_configs:
  - role: node
  relabel_configs:
  - action: labelmap
    regex: __meta_kubernetes_node_label_(.+)
  - source_labels: [__meta_kubernetes_node_name]
    regex: (.+)
    target_label: __address__
    replacement: ${1}:4194
[Source: 400-devops__06-Kubernetes__k8s-paas__07.Promtheus监控k8s企业级应用.md]

Sources