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

相关推荐
AKAMAI5 小时前
跳过复杂环节:Akamai应用平台让Kubernetes生产就绪——现已正式发布
人工智能·云原生·云计算
阿里云云原生11 小时前
不重启、不重写、不停机:SLS 软删除如何实现真正的“无感数据急救”?
云原生
Serverless社区1 天前
函数计算的云上计费演进:从请求驱动到价值驱动,助力企业走向 AI 时代
阿里云·云原生·serverless
资源开发与学习2 天前
Kubernetes集群核心概念 Service
kubernetes
阿里云云原生2 天前
【云栖大会】AI原生、AI可观测、AI Serverless、AI中间件,4场论坛20+议题公布!
云原生
容器魔方2 天前
Bloomberg 正式加入 Karmada 用户组!
云原生·容器·云计算
muyun28003 天前
Docker 下部署 Elasticsearch 8 并集成 Kibana 和 IK 分词器
elasticsearch·docker·容器
Nazi63 天前
k8s的dashboard
云原生·容器·kubernetes
傻傻虎虎3 天前
【Docker】常用帮忙、镜像、容器、其他命令合集(2)
运维·docker·容器
是小崔啊3 天前
叩丁狼K8s - 概念篇
云原生·容器·kubernetes