ch4. Replication and other controllers: deploying managed pods
4.4. Running exactly one pod on each node with daemonsets
소챕터들
- 4.1 keeping pods healthy
 - 4.2. introducing replicationcontrollers
 - 4.3. using replicasets instead of replicationcontroller
 - 4.4. running exactly one pod on each node with daemonset
 - 4.5. running pods that perform a single completable task
 - 4.6. scheduling jobs to run periodically or once in the future
 
Using a DaemonSet to run a pod on every node
DaemonSet object를 만들면 ReplicationController나 ReplicaSet과 흡사하지만 각각의 노드에 하나의 pod를 띄워준다.
Using a DaemonSet to run pods only on certain nodes
pod template의 node-Selector property를 사용해서 pod를 띄울 특정 node를 선택할 수 있다.
ssd 노드에서만 작동하는 ssd-monitor daemon을 만든다고 상상해보자. SSD를 가지고 있는 노드에서만 작동하는 DaemonSet을 만들고 SSD가 있는 노드에는 disk=ssd 라벨을 붙여준다.
5초마다 "SSD OK"를 출력하는 DaemonSet을 만들어보자. 저자가 이미 Docker Hub에 해당 이미지를 배포해 놓았기 때문ㅇ에 ssd-monitor-daemonset.yaml만 추가해보자.
apiVersion: apps/v1beta2           1
kind: DaemonSet                    1
metadata:
  name: ssd-monitor
spec:
  selector:
    matchLabels:
      app: ssd-monitor
  template:
    metadata:
      labels:
        app: ssd-monitor
    spec:
      nodeSelector:                2
        disk: ssd                  2
      containers:
      - name: main
        image: luksa/ssd-monitor- 2: pod template은 node selector 옵션을 포함하고, 이는 
disk=ssd라벨이 있는 노드에서만 pod를 띄워준다. 
DaemonSet object도 이제
apps/v1버전에서 작동한다. 위 예시에서 apiVersion을 변경해야 작동한다.
$ kubectl create -f ssd-monitor-daemonset.yaml
daemonset.apps/ssd-monitor created
$ kubectl get ds
NAME          DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE
ssd-monitor   0         0         0       0            0           disk=ssd        42s
$ kubectl get po
No resources found.아직 node에 disk=ssd 라벨을 붙이지 않았기 때문에 아무것도 나오지 않는다. node에 라벨을 붙여보자.
$ kubectl get node
NAME   STATUS     ROLES    AGE   VERSION
m01    NotReady   master   31d   v1.17.3
$ kubectl label node m01 disk=ssd
node/m01 labeled
$ kubectl get op
NAME                READY     STATUS    RESTARTS   AGE
ssd-monitor-hgxwq   1/1       Running   0          35s이제 node의 라벨을 변경하면 pod가 내려가는 것을 볼 수 있다.
$ kubectl label node m01 disk=hdd --overwrite
node/m01 labeled
$ kubectl get po
NAME                READY     STATUS        RESTARTS   AGE
ssd-monitor-hgxwq   1/1       Terminating   0          35s