DaemonSet
:確保所有節點都運行指定的Pod。隨著節點被加入到叢集中,Pod會自動被添加到新的節點。當從叢群刪除節點時,在節點上的Pod也會被刪除。刪除DaemonSet將清除它創建的Pod。
Daemonset.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
labels:
app: ubuntu
name: daemonset-demo
spec:
selector:
matchLabels:
app: ubuntu
template:
metadata:
labels:
app: ubuntu
spec:
tolerations:
- key: node-role.kubernetes.io/master
effect: NoSchedule
containers:
- name: ubuntu
image: ubuntu:20.04
args: [bash, -c, 'for ((i = 0; ; i++)); do echo "$i: $(date)"; sleep 100; done']
部屬Daemonset
root@master:/# kubectl apply -f daemonset.yaml
daemonset.apps/daemonset-demo created
查看Daemonset
root@master:/# kubectl get daemonset
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
daemonset-demo 2 2 1 2 1 <none> 3s
查看pod
root@c8master:/# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
daemonset-demo-9jcfr 1/1 Running 0 24s 10.244.1.150 node <none> <none>
daemonset-demo-djwmg 1/1 Running 0 24s 10.244.0.69 master <none> <none>
先刪除daemonset-demo-9jcfr
,再查看pod
root@master:/# kubectl delete pod daemonset-demo-9jcfr
pod "daemonset-demo-9jcfr" deleted
kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
daemonset-demo-48gj9 1/1 Running 0 8s 10.244.1.151 node <none> <none>
daemonset-demo-djwmg 1/1 Running 0 4m42s 10.244.0.69 master <none> <none>