CKA를 준비해보자 11일차 - DaemonSet

0

CKA

목록 보기
11/43

DaemonSets

DaemonSetDeployment와 비슷하게 pod를 관리하지만, 재밌게도 node마다 pod를 관리한다는 것이다.

가령, DaemonSet을 하나 만들어서 node마다 하나의 pod를 만들라고하면, node마다 하나의 pod씩이 만들어지고 DaemonSet이 이를 관리하는 것이다.

 ----------------------------
 |        DeamonSet         |
 ----------------------------
    |          |          | 
    |          |          |
--Node1--  --Node2--  --Node3--
|  pod1 |  |  pod2 |  |  pod3 |
---------  ---------  ---------

위의 그림과 같이 DaemonSet은 각 node마다 정의한 pod를 1개씩 배포한다. 만약 특정 node에서 pod가 다운되면, DaemonSet이 이를 확인하여 pod하나를 새로 다시 해당 node에 올려준다.

DaemonSet의 정의는 ReplicaSet과 거의 동일하다.

  • replicaset-definition.yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: monitoring-daemon
spec:
  selector:
    matchLabels:
      app: monitoring-daemon
  template:
    metadata:
      labels:
        app: monitoring-daemon
    spec:
      containers:
      - name: monitoring-daemon
        image: monitoring-daemon

ReplicaSetselectortemplate를 가지고 있는 것과 같이, DamonSet역시도 마찬가지이다.

  • daemon-set-definition.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: monitoring-daemon
spec:
  selector:
    matchLabels:
      app: monitoring-daemon
  template:
    metadata:
      labels:
        app: monitoring-daemon
    spec:
      nodeSelector:
        disk: ssd
      containers:
      - name: monitoring-daemon
        image: monitoring-daemon

거의 ReplicaSet과 동일한데, 재미난 점은 spec.nodeSelector의 target이 node라는 것이다. node가 가지고 있는 labelnodeSelector에 해당한다면 template에 있는 podnode에 배포하는 것이다. 여기서는 disk: ssd label을 가진 node에 template에 있는 pod를 배포하겠다는 것이다. 만약 nodeSelector로 target node를 쓰지 않으면 모든 node에 pod가 배포된다.

참고로 daemonsetreplicas가 없다. 따라서 node당 하나의 pod만 생성하는 로직이라고 생각하면 된다.

DeamonSet이 동작하는 방식은 매우 간단하다. default scheduler와 NodeAffinity를 사용하여 해당하는 node에 pod를 할당하고 모니터링하는 것이 전부이다.

이렇게 각 node마다 pod를 배포하고 관리한다는 측면에서 node의 자원량을 모니터링하거나 node에 저장된 각 pod log들을 가져온다는 측면에서 강점이 있다.

  • get damonsets
kubectl get daemonsets

만약 daemonset을 만들라는 문제가 나온다면, deployment를 만든 다음에 불필요한 값들을 삭제해주면 된다.

kubectl create deployment elasticsearch --image elasticsearch:latest --dry-run client -o yaml > daemonset.yaml

0개의 댓글