DaemonSet:简称DS,守护进程控制器
????????DS的主要作用,是在kubernetes集群里,运行一个daemon pod。DS只管理POD 对象,然后通过nodeAffinity和Toleration这两个调度器的小功能,保证每个节点上有且只有一个pod。
特征:
典型用法
案例:
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: daemon
labels:
app: nginx
spec:
revisionHistoryLimit: 10
selector:
matchLabels:
app: nginx
template:
metadata:
creationTimestamp: null
labels:
app: nginx
spec:
nodeSelector:
ds: "true"
containers:
- name: nginx
image: nginx:1.15.3
ports:
- containerPort: 80
name: nginx
updateStrategy:
#rollingUpdate:
# maxUnavailable: 1
#type: RollingUpdate
type: OnDelete
创建完成之后就可以看到在每个节点上有一个pod
[root@k8s-master-1 test]# kubectl get pod -owide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
busybox 1/1 Running 11 46h 10.244.1.85 k8s-node-2 <none> <none>
daemon-s5lnb 1/1 Running 0 7m1s 10.244.1.93 k8s-node-2 <none> <none>
daemon-wjv2k 1/1 Running 0 7m4s 10.244.0.120 k8s-node-1 <none> <none>
#如果不想在某一个节点创建DaemonSet,那么就给需要创建DS的节点打一个标签
[root@k8s-master-1 test]# kubectl label node k8s-node-2 ds=true
node/k8s-node-2 labeled
#然后在yaml文档中添加标签spec.template.spec.nodeSelector: ds="true"
#然后更新yaml文件
[root@k8s-master-1 test]# kubectl replace -f DaemonSet.yaml
daemonset.apps/daemon replaced
#就看到只在节点2上创建了DS
[root@k8s-master-1 test]# kubectl get pod -owide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
daemon-xwtz8 1/1 Running 0 9s 10.244.1.94 k8s-node-2 <none> <none>
DaemonSet的更新和回滚和Deployment相同
[root@k8s-master-1 test]# kubectl get node --show-labels 查看标签
[root@k8s-master-1 test]# kubectl rollout history ds daemon 查看历史版本记录
[root@k8s-master-1 test]# kubectl rollout undo ds daemon 回滚
[root@k8s-master-1 test]# kubectl set image ds daemon nginx=nginx:1.15.4 --record