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

相关推荐
天才奇男子5 小时前
HAProxy高级功能全解析
linux·运维·服务器·微服务·云原生
lpruoyu10 小时前
【Docker进阶-05】Docker网络
网络·docker·容器
人间打气筒(Ada)10 小时前
k8s:CNI网络插件flannel与calico
linux·云原生·容器·kubernetes·云计算·k8s
江畔何人初12 小时前
pod的内部结构
linux·运维·云原生·容器·kubernetes
三块钱079412 小时前
群晖docker部署Mattermost,对接openclaw
运维·docker·容器
周航宇JoeZhou13 小时前
JB2-7-HTML
java·前端·容器·html·h5·标签·表单
苦逼IT运维15 小时前
从 0 到 1 理解 Kubernetes:一次“破坏式”学习实践(一)
linux·学习·docker·容器·kubernetes
萧曵 丶15 小时前
Docker 面试题
运维·docker·容器
晨港飞燕15 小时前
容器,pod,节点概念
容器
腾讯云开发者15 小时前
言出法随 -- Chaterm如何通过ASR精准操作K8S
云原生·容器·kubernetes