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

相关推荐
Yeats_Liao6 分钟前
遗留系统微服务改造(一):遗留系统改造策略与实战场景分析
微服务·云原生·架构
dalianwawatou1 小时前
云原生-k8s
云原生·容器·kubernetes
荣光波比1 小时前
K8S(四)—— Kubectl从入门到精通:K8s资源管理与项目生命周期实战指南
云原生·容器·kubernetes
荣光波比1 小时前
K8S(五)—— K8s中YAML文件全方位解析:语法、案例、Port详解与快速编写技巧
云原生·容器·kubernetes
小诸葛的博客1 小时前
详解istio mtls双向身份认证
云原生·istio
2301_787328494 小时前
24.集群及高可用-Keepalived
linux·运维·云原生
java_logo5 小时前
n8n Docker 部署手册
运维·docker·容器
张忠琳5 小时前
volcano scheduler v1.3.0源码分析之启动流程
云原生·kubernetes·volcano
東雪蓮☆7 小时前
K8S 概念、安装与核心工作机制详解
linux·运维·云原生·容器·kubernetes
安安csdn8 小时前
k8s存储juicefs简介
docker·容器·kubernetes