> 文档中心 > k8s node_exporter部署

k8s node_exporter部署


相关链接

docker hub链接:https://hub.docker.com/r/prom/node-exporter
node exporter yaml: https://github.com/bibinwilson/kubernetes-prometheus

部署

[root@k8s-master-1 prometheus]# cat namespace.yaml apiVersion: v1kind: Namespacemetadata:  name: prometheus[root@k8s-master-1 prometheus]# cat node_exporter.yaml apiVersion: apps/v1kind: DaemonSetmetadata:  name: node-exporter  namespace: prometheus  labels:    name: node-exporterspec:  selector:    matchLabels:     name: node-exporter  template:    metadata:      labels: name: node-exporter    spec:      tolerations:      - key: "node-role.kubernetes.io/master" operator: "Exists" effect: "NoSchedule"      hostPID: true      hostIPC: true      hostNetwork: true # hostNetwork hostIPC hostPID都为True时,表示这个Pod里的所有容器会直接使用宿主机的网络,直接与宿主机进行IPC(进程间通信通信,可以看到宿主机里正在运行的所有进程。   # 加入了hostNetwork:true会直接将我们的宿主机的9100端口映射出来,从而不需要创建service在我们的宿主机上就会有一个 9100的端口      containers:      - name: node-exporter image: prom/node-exporter:v0.16.0 ports: - containerPort: 9100 resources:   requests:     cpu: 0.15   # 这个容器运行至少需要0.15核cpu securityContext:   privileged: true # 开启特权模式 args: - --path.procfs    # 配置挂载宿主机(node节点)的路径 - /host/proc - --path.sysfs     # 配置挂载宿主机(node节点)的路径 - /host/sys - --collector.filesystem.ignored-mount-points  # 通过正则表达式忽略某些文件系统挂载点的信息收集 - '"^/(sys|proc|dev|host|etc)($|/)"' volumeMounts: # 将主机/dev /proc /sys 这些目录挂在到容器中,这是因为我们采集的很多节点数据都是通过这些文件来获取系统信息的。 - name: dev   mountPath: /host/dev - name: proc   mountPath: /host/proc - name: sys   mountPath: /host/sys - name: rootfs   mountPath: /rootfs      volumes:      - name: proc hostPath:   path: /proc      - name: dev hostPath:   path: /dev      - name: sys hostPath:   path: /sys      - name: rootfs hostPath:   path: /
# 查看部署[root@k8s-master-1 prometheus]# kubectl get pods -n prometheusNAME    READY   STATUS    RESTARTS   AGEnode-exporter-m6jmm   1/1     Running   0   4m8snode-exporter-zm78t   1/1     Running   0   4m8s# 获取CPU指标# HELP 解释当前指标的含义,上面表示在每种模式下# TYPE 说明当前指标的数据类型[root@k8s-master-1 prometheus]# curl -s http://localhost:9100/metrics | grep -i cpu | head -n 10# HELP go_memstats_gc_cpu_fraction The fraction of this program's available CPU time used by the GC since the program started.# TYPE go_memstats_gc_cpu_fraction gaugego_memstats_gc_cpu_fraction 6.608966775338419e-06# HELP node_cpu_guest_seconds_total Seconds the cpus spent in guests (VMs) for each mode.# TYPE node_cpu_guest_seconds_total counternode_cpu_guest_seconds_total{cpu="0",mode="nice"} 0node_cpu_guest_seconds_total{cpu="0",mode="user"} 0node_cpu_guest_seconds_total{cpu="1",mode="nice"} 0node_cpu_guest_seconds_total{cpu="1",mode="user"} 0# HELP node_cpu_seconds_total Seconds the cpus spent in each mode.