# 什么是DaemonSet?
在K8s集群中的每一个Node中都会运行一个Pod的控制器。
使用场景是?
- 日志收集,每个节点运行一个Pod用于收集容器产生的日志
- 监控管理,每个节点运行一个pod用于监控节点的状态
- 网络应用,每个节点运行一个Pod用于将节点加入k8s网络
# 使用DaemonSet
使用yaml描述DaemonSet对象
代码语言:javascript复制apiVersion: apps/v1
kind: DaemonSet
metadata:
name: nginx-ds
labels:
k8s-app: nginx-ds
spec:
selector:
matchLabels:
name: nginx-ds
template:
metadata:
labels:
name: nginx-ds
spec:
containers:
- name: nginx-ds
image: nginx
创建DaemonSet对象,会看到自动的每一个节点中都创建了一个pod。
代码语言:javascript复制[root@k8s-worker1 zwf]# kubectl apply -f daemonset.yaml -n zwf
daemonset.apps/nginx-ds configured
[root@k8s-worker1 zwf]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master Ready <none> 32d v1.23.4
k8s-worker1 Ready <none> 152d v1.23.4
k8s-worker2 Ready <none> 152d v1.23.4
[root@k8s-worker1 zwf]# kubectl get ds -n zwf
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
nginx-ds 3 3 3 3 3 <none> 4m2s
[root@k8s-worker1 zwf]# kubectl get pods -n zwf -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-ds-7w2kx 1/1 Running 0 81s 10.222.194.73 k8s-worker1 <none> <none>
nginx-ds-l5lmx 1/1 Running 0 46s 10.222.126.38 k8s-worker2 <none> <none>
nginx-ds-zdfgl 1/1 Running 0 82s 10.222.235.217 k8s-master <none> <none>