交付node-exporter

node-exporter官方dockerhub地址

node-expoerer官方github地址

准备镜像

1
2
3
4
5
[root@ops-200 ~]# docker pull prom/node-exporter:v0.18.1
[root@ops-200 ~]# docker images|grep node-exporter
prom/node-exporter v0.18.1 e5a616e4b9cf 10 months ago 22.9MB
[root@ops-200 ~]# docker tag e5a616e4b9cf harbor.od.com/public/node-exporter:v0.18.1
[root@ops-200 ~]# docker push harbor.od.com/public/node-exporter:v0.18.1

准备资源配置清单

创建资源目录

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

编写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
[root@ops-200 node-exporter]# vim daemonset.yaml
kind: DaemonSet
apiVersion: apps/v1
metadata:
name: node-exporter
namespace: kube-system
labels:
daemon: "node-exporter"
grafanak8sapp: "true"
spec:
selector:
matchLabels:
daemon: "node-exporter"
grafanak8sapp: "true"
template:
metadata:
name: node-exporter
labels:
daemon: "node-exporter"
grafanak8sapp: "true"
spec:
volumes:
- name: proc
hostPath:
path: /proc
type: ""
- name: sys
hostPath:
path: /sys
type: ""
containers:
- name: node-exporter
image: harbor.od.com/public/node-exporter:v0.18.1
imagePullPolicy: IfNotPresent
args:
- --path.procfs=/host_proc
- --path.sysfs=/host_sys
ports:
- name: node-exporter
hostPort: 9100
containerPort: 9100
protocol: TCP
volumeMounts:
- name: sys
readOnly: true
mountPath: /host_sys
- name: proc
readOnly: true
mountPath: /host_proc
hostNetwork: true

应用资源配置清单

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

查看数据

1
2
3
4
5
[root@k8s01-21 ~]# kubectl get pod -n kube-system -o wide|grep node-exporter
node-exporter-bm6k9 1/1 Running 0 94s 192.168.1.21 k8s01-21.host.com <none> <none>
node-exporter-ltlm9 1/1 Running 0 94s 192.168.1.23 k8s03-23.host.com <none> <none>
node-exporter-r7w4d 1/1 Running 0 94s 192.168.1.22 k8s02-22.host.com <none> <none>
[root@k8s01-21 ~]# curl 192.168.1.23:9100/metrics