각각의 노드에서 같은 셀렉터(레이블)를 갖고 있는 파드를 한 개씩 생성하고 실행하는 컨트롤러이며 롤링 업데이트 및 롤백 기능 제공
▶ 주로 로그 수집기, 모니터링 에이전트와 같은 프로그램을 실행하는 파드를 생성할 때 사용됨
[root@master ~/kube/07/ds]# kubectl api-resources | grep Daemon
daemonsets ds apps/v1 true DaemonSet
[root@master ~/kube/07/ds]# vi nginx-ds.yaml
[root@master ~/kube/07/ds]# cat nginx-ds.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: nginx-ds
spec:
selector:
matchLabels:
app: webui
template:
metadata:
name: nginx-pod
labels:
app: webui
spec:
containers:
- name: nginx-container
image: nginx:1.14
[root@master ~/kube/07/ds]# kubectl apply -f nginx-ds.yaml
daemonset.apps/nginx-ds created
[root@master ~/kube/07/ds]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-ds-7n2lx 1/1 Running 0 8s 10.233.102.159 node1 <none> <none>
nginx-ds-mm5bg 1/1 Running 0 7s 10.233.71.26 node3 <none> <none>
nginx-ds-qpsv9 1/1 Running 0 7s 10.233.75.41 node2 <none> <none>
▶ 각 노드에 하나씩 생긴 것을 확인할 수 있음
[root@master ~/kube/07/ds]# kubectl get daemonsets.apps
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
nginx-ds 3 3 3 3 3 <none> 77s
[root@master ~/kube/07/ds]# kubectl describe daemonsets.apps nginx-ds
Name: nginx-ds
Selector: app=webui
Node-Selector: <none>
Labels: <none>
Annotations: deprecated.daemonset.template.generation: 1
Desired Number of Nodes Scheduled: 3
Current Number of Nodes Scheduled: 3
Number of Nodes Scheduled with Up-to-date Pods: 3
Number of Nodes Scheduled with Available Pods: 3
Number of Nodes Misscheduled: 0
Pods Status: 3 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
Labels: app=webui
Containers:
nginx-container:
Image: nginx:1.14
Port: <none>
Host Port: <none>
Environment: <none>
Mounts: <none>
Volumes: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulCreate 82s daemonset-controller Created pod: nginx-ds-7n2lx
Normal SuccessfulCreate 82s daemonset-controller Created pod: nginx-ds-qpsv9
Normal SuccessfulCreate 82s daemonset-controller Created pod: nginx-ds-mm5bg
▶ pod는 daemonset-controller에 의해 생성됨
kube-system에서 daemonset으로 구동되는 리소스 확인
[root@master ~/kube/07/ds]# kubectl get ds -n kube-system
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
calico-node 4 4 4 4 4 kubernetes.io/os=linux 27h
kube-proxy 4 4 4 4 4 kubernetes.io/os=linux 27h
nodelocaldns 4 4 4 4 4 kubernetes.io/os=linux 27h
▶ kube-system에 있는 pod 들과 다르게 master에 사용자 정의 daemonset이 뜨지 않는 이유는 기본적으로 taint가 걸려있기때문
[root@master ~/kube/07/ds]# kubectl describe nodes | grep Taint
Taints: node-role.kubernetes.io/control-plane:NoSchedule
Taints: <none>
Taints: <none>
Taints: <none>
[root@master ~/kube/07/ds]# kubectl taint nodes master node-role.kubernetes.io/control-plane:NoSchedule-
node/master untainted
[root@master ~/kube/07/ds]# kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-ds-7n2lx 1/1 Running 0 9m12s
nginx-ds-mm5bg 1/1 Running 0 9m11s
nginx-ds-qpsv9 1/1 Running 0 9m11s
nginx-ds-r49tr 0/1 ContainerCreating 0 4s
[root@master ~/kube/07/ds]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-ds-7n2lx 1/1 Running 0 9m20s 10.233.102.159 node1 <none> <none>
nginx-ds-mm5bg 1/1 Running 0 9m19s 10.233.71.26 node3 <none> <none>
nginx-ds-qpsv9 1/1 Running 0 9m19s 10.233.75.41 node2 <none> <none>
nginx-ds-r49tr 1/1 Running 0 12s 10.233.97.133 master <none> <none>
▶ Taint를 풀어주면 자동으로 생성되는 것을 확인할 수 있음
[root@master ~/kube/07/ds]# kubectl taint nodes master node-role.kubernetes.io/control-plane:NoSchedule
node/master tainted