[root@k8smaster43-11 CSDN]# kubectl create -f daemonset.yaml
daemonset.apps/tomcat-daemons created
[root@k8smaster43-11 CSDN]#
[root@k8smaster43-11 CSDN]# kubectl get ds,pod -o wide --show-labels
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE CONTAINERS IMAGES SELECTOR LABELS
daemonset.apps/tomcat-daemons 2 2 2 2 2 <none> 39s demo-tomcat tomcat:8.0 app=tomcat <none>NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES LABELS
pod/tomcat-daemons-dqfn4 1/1 Running 0 39s 10.244.2.81 k8sworker43-22 <none> <none> app=tomcat,controller-revision-hash=7f5c98c9cc,pod-template-generation=1
pod/tomcat-daemons-tpz7z 1/1 Running 0 39s 10.244.1.98 k8sworker43-21 <none> <none> app=tomcat,controller-revision-hash=7f5c98c9cc,pod-template-generation=1
[root@k8smaster43-11 CSDN]#
將1臺工作節點從Kubernetes集群中剔除,則DaemonSet的Pod會從該節點刪除:
[root@k8smaster43-11 CSDN]# kubectl delete nodes/k8sworker43-21
node "k8sworker43-21" deleted
[root@k8smaster43-11 CSDN]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8smaster43-11 Ready master 107d v1.19.4
k8sworker43-22 Ready <none> 107d v1.19.4
[root@k8smaster43-11 CSDN]#
[root@k8smaster43-11 CSDN]# kubectl get ds,pod -o wide --show-labels
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE CONTAINERS IMAGES SELECTOR LABELS
daemonset.apps/tomcat-daemons 1 1 1 1 1 <none> 8m19s demo-tomcat tomcat:8.0 app=tomcat <none>NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES LABELS
pod/tomcat-daemons-dqfn4 1/1 Running 0 8m19s 10.244.2.81 k8sworker43-22 <none> <none> app=tomcat,controller-revision-hash=7f5c98c9cc,pod-template-generation=1
[root@k8smaster43-11 CSDN]#
將1臺工作節點加入Kubernetes集群中,則DaemonSet會自動從該節點啟動Pod:
# 在工作節點執行kubeadm join命令加入集群
[root@k8sworker43-21 ~]# kubeadm join 192.168.43.11:6443 --token d1ncs0.we7r79976ndaf3k4 --discovery-token-ca-cert-hash sha256:28d33e6003840de19700fbba569f32557c57841ff94516720eadc072e4b3a099
[preflight] Running pre-flight checks
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml'
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Starting the kubelet
[kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.Run 'kubectl get nodes' on the control-plane to see this node join the cluster.
[root@k8sworker43-21 ~]# #在Master節點查看DaemonSet資源情況
[root@k8smaster43-11 CSDN]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8smaster43-11 Ready master 107d v1.19.4
k8sworker43-21 Ready <none> 12s v1.19.4
k8sworker43-22 Ready <none> 107d v1.19.4
[root@k8smaster43-11 CSDN]#
[root@k8smaster43-11 CSDN]# kubectl get ds,pod -o wide --show-labels
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE CONTAINERS IMAGES SELECTOR LABELS
daemonset.apps/tomcat-daemons 2 2 2 2 2 <none> 20m demo-tomcat tomcat:8.0 app=tomcat <none>NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES LABELS
pod/tomcat-daemons-cvxrb 1/1 Running 0 10s 10.244.1.2 k8sworker43-21 <none> <none> app=tomcat,controller-revision-hash=7f5c98c9cc,pod-template-generation=1
pod/tomcat-daemons-dqfn4 1/1 Running 0 20m 10.244.2.81 k8sworker43-22 <none> <none> app=tomcat,controller-revision-hash=7f5c98c9cc,pod-template-generation=1
[root@k8smaster43-11 CSDN]#