k8s 部署 node exporter

创建namespace

node-exporter-namespace.yaml

apiVersion: v1
kind: Namespace
metadata:
  name: ns-monitor

拉取镜像

quay.io/prometheus/node-exporter:v0.18.1

node exporter的DaemonSet

node-exporter-daemonSet.yaml

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: node-exporter
  namespace:  ns-monitor
  labels:
    name: node-exporter
spec:
  selector:
    matchLabels:
     name: node-exporter
  template:
    metadata:
      labels:
        name: node-exporter
    spec:
      containers:
      - name: node-exporter
        image: quay.io/prometheus/node-exporter:v0.18.1
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 9100
        resources:
          requests:
            cpu: 0.15
        securityContext:
          privileged: true
        args:
        - --path.procfs
        - /host/proc
        - --path.sysfs
        - /host/sys
        - --collector.filesystem.ignored-mount-points
        - '"^/(sys|proc|dev|host|etc)($|/)"'
        volumeMounts:
        - name: dev
          mountPath: /host/dev
        - name: proc
          mountPath: /host/proc
        - name: sys
          mountPath: /host/sys
        - name: rootfs
          mountPath: /rootfs
      tolerations:
      - key: "node-role.kubernetes.io/master"
        operator: "Exists"
        effect: "NoSchedule"
      volumes:
        - name: proc
          hostPath:
            path: /proc
        - name: dev
          hostPath:
            path: /dev
        - name: sys
          hostPath:
            path: /sys
        - name: rootfs
          hostPath:
            path: /

node exporter的service

node-exporter-service.yaml

apiVersion: v1
kind: Service
metadata:
  labels:
    k8s-app: node-exporter
  name: node-exporter
  namespace: ns-monitor
spec:
  ports:
  - name: http
    port: 9100
	targetPort:9100
    nodePort: 31672
    protocol: TCP
  type: NodePort
  selector:
    name: node-exporter

如果不使用Service部署,而使用hostNetwork方式部署可以不需要node-exporter-service.yaml文件。直接使用一下node-exporter-daemonSet.yaml即可

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: node-exporter
  namespace:  ns-monitor
  labels:
    name: node-exporter
spec:
  selector:
    matchLabels:
     name: node-exporter
  template:
    metadata:
      labels:
        name: node-exporter
    spec:
	  hostPID: true        # 使用主机的PID
      hostIPC: true        # 使用主机的IPC
      hostNetwork: true    # 使用主机的网络
      containers:
      - name: node-exporter
        image: quay.io/prometheus/node-exporter:v0.18.1
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 9100
        resources:
          requests:
            cpu: 0.15
        securityContext:
          privileged: true
        args:
        - --path.procfs
        - /host/proc
        - --path.sysfs
        - /host/sys
        - --collector.filesystem.ignored-mount-points
        - '"^/(sys|proc|dev|host|etc)($|/)"'
        volumeMounts:
        - name: dev
          mountPath: /host/dev
        - name: proc
          mountPath: /host/proc
        - name: sys
          mountPath: /host/sys
        - name: rootfs
          mountPath: /rootfs
      tolerations:
      - key: "node-role.kubernetes.io/master"
        operator: "Exists"
        effect: "NoSchedule"
      volumes:
        - name: proc
          hostPath:
            path: /proc
        - name: dev
          hostPath:
            path: /dev
        - name: sys
          hostPath:
            path: /sys
        - name: rootfs
          hostPath:
            path: /

多增加了

	  hostPID: true        # 使用主机的PID
      hostIPC: true        # 使用主机的IPC
      hostNetwork: true    # 使用主机的网络

启动

kubectl apply -f node_export-namespace.yaml
kubectl apply -f .

查看

kubectl get pod -n ns-monitor -o wide
kubectl get svc -n ns-monitor

访问

http://10.0.2.13:31672

10.0.2.13为宿主机的ip,31672为node exporter service的port

相关推荐
运维&陈同学39 分钟前
【Beats01】企业级日志分析系统ELK之Metricbeat与Heartbeat 监控
运维·elk·elasticsearch·云原生·kibana·heartbeat·metricbeat
AKA小徐1 小时前
Debian12使用RKE2离线部署3master2node三主两从的k8s集群详细教程
kubernetes·rancher·rke2
老大白菜8 小时前
Windows 11 安装 Dify 完整指南 非docker环境
windows·docker·容器
tntlbb12 小时前
Ubuntu20.4 VPN+Docker代理配置
运维·ubuntu·docker·容器
Gabriel_liao13 小时前
Docker安装Neo4j
docker·容器·neo4j
有一个好名字13 小时前
zookeeper分布式锁模拟12306买票
分布式·zookeeper·云原生
Anna_Tong16 小时前
云原生大数据计算服务 MaxCompute 是什么?
大数据·阿里云·云原生·maxcompute·odps
豆豆豆豆变16 小时前
Docker轻量级可视化工具Portainer
docker·容器·自动化运维
花晓木16 小时前
k8s etcd 数据损坏处理方式
容器·kubernetes·etcd
运维&陈同学16 小时前
【模块一】kubernetes容器编排进阶实战之基于velero及minio实现etcd数据备份与恢复
数据库·后端·云原生·容器·kubernetes·etcd·minio·velero