클라우드,가상화/K8S

k8s - DemonSet

aiemag 2023. 10. 23. 18:24
반응형

DemonSet?

 

DemonSet은 각 노드에 파드를 하나씩 배치.

※ replicaset은 각 kubernetes node에 총 N개의 파드를 노드의 리소스 상황에 맞게 배치.

※ demonset은 repica 수를 지정할 수 없고 하나의 노드에 두 개의 파드를 배치할 수도 없음.

※ demonset은 모니터링이나 로그 전송과 같은 용도로 많이 사용.

 

 

DemonSet 특징

- demonset은 파드를 배치하고 싶지 않은 노드가 있을 경우 nodeSelector나 노드 anti pod affinity를 사용한 스케줄링으로 예외 처리 할 수 있음.

※ anti pod affinity: inter pod affinity 와는 반대로 특정 파드와 함께 배포되는 것을 피하도록 배포될 노드를 결정.

- kubernetes node를 늘렸을 때도 demonset의 파드는 자동으로 늘어난 노드에서 기동.

- demonset은 각 파드가 출력하는 로그를 호스트 단위로 수집하는 Fluentd나 각 파드 리소스 사용 현황 및 노드 상태를 모니터링하는 Datadog 등 모든 노드에서 반드시 동작해야 하는 프로세스를 위해 사용하는 것이 유용.

 

 

DemonSet 생성

sample-ds.yaml

※ replicaset 등과 달리 replica 수 등을 지정할 수 있는 항목이 없음.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: sample-ds
spec:
  selector:
    matchLabels:
      app: sample-app
  template:
    metadata:
      labels:
        app: sample-app
    spec:
      containers:
      - name: nginx-container
        image: nginx:1.16
cs

 

실행

[root@k8s-master daemonset]# k apply -f sample-ds.yaml
daemonset.apps/sample-ds created

 

각 노드에 하나씩 파드가 기동된 것을 확인

[root@k8s-master daemonset]# k get pods -o wide
NAME              READY   STATUS    RESTARTS   AGE   IP                NODE          NOMINATED NODE   READINESS GATES
sample-ds-h665a   1/1     Running   0          82s   192.168.194.111   k8s-worker1   <none>           <none>

NAME              READY   STATUS    RESTARTS   AGE   IP                NODE          NOMINATED NODE   READINESS GATES
sample-ds-h665b   1/1     Running   0          82s   192.168.194.112   k8s-worker2   <none>           <none>

NAME              READY   STATUS    RESTARTS   AGE   IP                NODE          NOMINATED NODE   READINESS GATES
sample-ds-h665c   1/1     Running   0          82s   192.168.194.113   k8s-worker3   <none>           <none>

 

DemonSet 업데이트 전략

Deployment와 마찬가지로 2가지 업데이트 전략 중 하나를 선택할 수 있음.

 

OnDelete

업데이트는 다음 번에 다시 생성할 때나 수동으로 임의의 시점에 함.

파드가 정지되어 다시 생성되기 전까지는 업데이트되지 않음.

※ 운영상의 이유로 정지하면 안 되는 파드이거나 업데이트가 급하게 필요 없는 경우 OnDelete 설정으로 사용해도 되지만, 이전 버전이 계속 장기간 사용된다는 점에 주의.

 

sample-ds-ondelete.yaml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: sample-ds-ondelete
spec:
  updateStrategy:
   type: OnDelete
  selector:
    matchLabels:
      app: sample-app
  template:
    metadata:
      labels:
        app: sample-app
    spec:
      containers:
      - name: nginx-container
        image: nginx:1.16
cs

 

 

임의의 시점에 파드를 업데이트하는 경우에는 Demonset과 연결된 파드를 kubectl delete pod 명령으로 수동으로 정지시키고 자동화된 복구 기능으로 새로운 파드를 생성해야 함.

 

실행

[root@k8s-master daemonset]# k delete pod sample-ds-ondelete-bdnw4

 

RollingUpdate

Daemonse에서는 하나의 노드에 동일한 파드를 여러 개 생성할 수 없으므로 Deployment와 달리 동시에 생성할 수 있는 최대 파드 수(maxSurge)를 설정할 수 없음.

 

동시에 정지 가능한 최대 파드 수(maxUnavailable)만 지정하여 RollingUpdate를 하게 됨.

※ maxUnavilable의 기본값은 1, maxUnavailable을 0으로 지정할 수 없음.

 

sample-ds-rollingupdate.yaml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: sample-ds-rollingupdate
spec:
  updateStrategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavilable: 2
  selector:
    matchLabels:
      app: sample-app
  template:
    metadata:
      labels:
        app: sample-app
    spec:
      containers:
      - name: nginx-container
        image: nginx:1.16
cs

 

 

 

반응형

'클라우드,가상화 > K8S' 카테고리의 다른 글

k8s - Secret  (0) 2023.12.17
k8s - ClusterIP  (0) 2023.07.17
k8s - kubernetes 클러스터 네트워크와 서비스  (0) 2023.07.16
k8s - Deployment  (0) 2023.07.02
k8s - ReplicaSet  (0) 2023.07.02