DaemonSet会在集群的每一个Node上创建唯一的一个Pod,通常用来运行一些需要执行系统级别、与基础结构相关的操作的Pod。例如,希望在每个Node上运行日志收集器和资源监控器。
apiVersion: apps/v1 # 注意DaemonSet资源所属的API组
kind: DaemonSet
metadata:
name: node-exporter-daemonset
spec: # DaemonSet的规格
selector: # (必须)匹配Pod的标签。可以使用matchLabels或matchExpressions
matchLabels:
app: prometheus
template: # Pod的模板
metadata:
labels: # 设定Pod的labels
app: prometheus
spec:
nodeSelector: # Pod的Node选择器,只在具有该标签的Node上部署Pod;若没有该选择器,则会在集群中的所有Node上部署
gpu: "true"
hostNetwork: true # 设定网络模式,hostNetwork表示与主机相同的协议栈
containers:
- name: node-exporter
image: prom/node-exporter
imagePullPolicy: IfNotPresent # 镜像拉取规则
command: # 镜像执行的命令
- /bin/node_exporter
- --path.procfs
- /host/proc
- --path.sysfs
- /host/sys
- --collector.filesystem.ignored-mount-points
- ^/(sys|proc|dev|host|etc)($|/)
volumeMounts:
- name: proc
mountPath: /host/proc
- name: sys
mountPath: /host/sys
- name: root
mountPath: /rootfs
volumes:
- name: proc
hostPath:
path: /proc
- name: sys
hostPath:
path: /sys
- name: root
hostPath:
path: /