首页 公告 项目 RSS

k8s安装node-exporter

September 26, 2022 本文有 356 个字 需要花费 1 分钟阅读

简介

简单的记录下

操作

首先创建node-exporter的daemonset

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

      hostPID: true
      hostNetwork: true

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

接着就是创建一个svc

---
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

      - 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