交付cadviso

cadvisor官方dockerhub地址

cadvisor官方github地址

准备镜像

1
2
3
4
5
[root@ops-200 ~]# docker pull google/cadvisor:v0.33.0
[root@ops-200 ~]# docker images|grep cadvisor
google/cadvisor v0.33.0 752d61707eac 13 months ago 68.6MB
[root@ops-200 ~]# docker tag 752d61707eac harbor.od.com/public/cadvisor:v0.33.0
[root@ops-200 ~]# docker push harbor.od.com/public/cadvisor:v0.33.0

准备资源配置清单

创建资源目录

1
2
[root@ops-200 ~]# mkdir /data/k8s-yaml/cadvisor
[root@ops-200 ~]# cd /data/k8s-yaml/cadvisor

编写yaml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
[root@ops-200 cadvisor]# vim daemonset.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: cadvisor
namespace: kube-system
labels:
app: cadvisor
spec:
selector:
matchLabels:
name: cadvisor
template:
metadata:
labels:
name: cadvisor
spec:
hostNetwork: true
tolerations:
- key: node-role.kubernetes.io/master
effect: NoSchedule
containers:
- name: cadvisor
image: harbor.od.com/public/cadvisor:v0.33.0
imagePullPolicy: IfNotPresent
volumeMounts:
- name: rootfs
mountPath: /rootfs
readOnly: true
- name: var-run
mountPath: /var/run
- name: sys
mountPath: /sys
readOnly: true
- name: docker
mountPath: /var/lib/docker
readOnly: true
ports:
- name: http
containerPort: 4194
protocol: TCP
readinessProbe:
tcpSocket:
port: 4194
initialDelaySeconds: 5
periodSeconds: 10
args:
- --housekeeping_interval=10s
- --port=4194
terminationGracePeriodSeconds: 30
volumes:
- name: rootfs
hostPath:
path: /
- name: var-run
hostPath:
path: /var/run
- name: sys
hostPath:
path: /sys
- name: docker
hostPath:
path: /data/docker

修改运算节点软链接

1
2
[root@k8s01-21 ~]# mount -o remount,rw /sys/fs/cgroup/
[root@k8s01-21 ~]# ln -s /sys/fs/cgroup/cpu,cpuacct /sys/fs/cgroup/cpuacct,cpu

应用资源配置清单

1
2
[root@ops-200 cadvisor]# kubectl apply -f daemonset.yaml
daemonset.apps/cadvisor created

查看数据

1
2
3
4
5
[root@k8s01-21 ~]# kubectl get pod -n kube-system -o wide|grep cadvisor
cadvisor-cxgts 1/1 Running 0 7m38s 192.168.1.23 k8s03-23.host.com <none> <none>
cadvisor-kc8g7 1/1 Running 0 7m38s 192.168.1.22 k8s02-22.host.com <none> <none>
cadvisor-klm7j 1/1 Running 0 7m38s 192.168.1.21 k8s01-21.host.com <none> <none>
[root@k8s01-21 ~]# curl 192.168.1.21:4194/metrics