官方文档: https://github.com/google/cadvisor/tree/master/deploy/kubernetes/base

先创建命名空间

kubectl create ns cadvisor
vim  daemonset.yaml 
vim  serviceaccount.yaml

对应文件内容如下

daemonset.yaml

apiVersion: apps/v1 # for Kubernetes versions before 1.9.0 use apps/v1beta2
kind: DaemonSet
metadata:
  name: cadvisor
  namespace: cadvisor
  annotations:
      seccomp.security.alpha.kubernetes.io/pod: 'docker/default'
spec:
  selector:
    matchLabels:
      name: cadvisor
  template:
    metadata:
      labels:
        name: cadvisor
    spec:
      serviceAccountName: cadvisor
      containers:
      - name: cadvisor
        image: ccr.ccs.tencentyun.com/cxaou/cadvisor:v0.45.0
        resources:
          requests:
            memory: 400Mi
            cpu: 400m
          limits:
            memory: 2000Mi
            cpu: 800m
        volumeMounts:
        - name: rootfs
          mountPath: /rootfs
          readOnly: true
        - name: var-run
          mountPath: /var/run
          readOnly: true
        - name: sys
          mountPath: /sys
          readOnly: true
        - name: docker
          mountPath: /var/lib/docker
          readOnly: true
        - name: disk
          mountPath: /dev/disk
          readOnly: true
        ports:
          - name: http
            containerPort: 8080
            protocol: TCP
      automountServiceAccountToken: false
      terminationGracePeriodSeconds: 30
      volumes:
      - name: rootfs
        hostPath:
          path: /
      - name: var-run
        hostPath:
          path: /var/run
      - name: sys
        hostPath:
          path: /sys
      - name: docker
        hostPath:
          path: /var/lib/docker
      - name: disk
        hostPath:
          path: /dev/disk

serviceaccount.yaml

apiVersion: v1
kind: ServiceAccount
metadata:
  name: cadvisor
  namespace: cadvisor

创建对应的对象

kubectl apply -f serviceaccount.yaml 
kubectl apply -f daemonset.yaml 

prometheus 进行接入,修改prometheus.yml

  - job_name: "cdvisor"
    static_configs:
      - targets: ["192.168.10.3:8080","192.168.20.33:8080"]

重启prometheus

systemctl restart prometheus.service 

general 查看

导入ID 14282