k8s安装node-exporter

简介

简单的记录下

操作

首先创建node-exporter的daemonset

 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
apiVersion: apps/v1
kind: DaemonSet
metadata:
  labels:
    app: node-exporter
  name: node-exporter
  namespace: app
spec:
  selector:
    matchLabels:
      app: node-exporter
  template:
    metadata:
      labels:
        app: node-exporter
    spec:
      hostPID: true
      hostNetwork: true
      containers:
      - args:
        - --path.rootfs=/host
        name: node-exporter
        image: prom/node-exporter:v1.3.1
        ports:
          - containerPort: 9100
            protocol: TCP
        volumeMounts:
        - mountPath: /host
          name: root
          readOnly: true
      volumes:
      - hostPath:
          path: /
        name: root

这里需要把系统中的根目录挂载到容器中,为了安全需要设置readonly,然后配置node-exporter的参数--path.rootfs=/host

接着下面两个参数需要设置为true

1
2
      hostPID: true
      hostNetwork: true

这样就可以监控系统的进程和网络

接着就是创建一个svc

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
---
kind: Service
apiVersion: v1
metadata:
  name: node-exporter
  namespace: app
spec:
  selector:
      app: node-exporter
  ports:
  - name: node-exporter
    protocol: TCP
    port: 9100
    targetPort: 9100

之后创建prometheus的job

1
2
3
4
5
6
7
      - job_name: 'rpi'
        kubernetes_sd_configs:
          - role: endpoints
        relabel_configs:
        - source_labels: [__meta_kubernetes_endpoints_name]
          regex: 'node-exporter'
          action: keep

因为是使用了kubernetes_sd_configs所以对应的service account和权限都要创建,详细的可以看

https://www.bboy.app/2022/09/23/prometheus%E7%9B%91%E6%8E%A7k3s/

欢迎关注我的博客 www.bboy.app

Have Fun