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

相关推荐
昌sit!3 小时前
K8S node节点没有相应的pod镜像运行故障处理办法
云原生·容器·kubernetes
A ?Charis6 小时前
Gitlab-runner running on Kubernetes - hostAliases
容器·kubernetes·gitlab
wclass-zhengge6 小时前
Docker篇(Docker Compose)
运维·docker·容器
茶馆大橘6 小时前
微服务系列五:避免雪崩问题的限流、隔离、熔断措施
java·jmeter·spring cloud·微服务·云原生·架构·sentinel
北漂IT民工_程序员_ZG7 小时前
k8s集群安装(minikube)
云原生·容器·kubernetes
coding侠客7 小时前
揭秘!微服务架构下,Apollo 配置中心凭啥扮演关键角色?
微服务·云原生·架构
梦魇梦狸º10 小时前
腾讯轻量云服务器docker拉取不到镜像的问题:拉取超时
docker·容器·github
南猿北者12 小时前
docker镜像仓库常用命令
运维·docker·容器
2301_8061313613 小时前
Kubernetes的基本构建块和最小可调度单元pod-0
云原生·容器·kubernetes
SilentCodeY14 小时前
containerd配置私有仓库registry
容器·kubernetes·containerd·镜像·crictl