DaemonSet

DaemonSet은 모든 노드(또는 선택된 노드)에 Pod의 복제본을 하나씩 실행하도록 보장하는 쿠버네티스 워크로드 리소스입니다. 클러스터에 노드가 추가되면 자동으로 해당 노드에 Pod가 추가되고, 노드가 제거되면 해당 Pod도 제거됩니다.

특징

Deployment와의 차이점

클라우드 네트워크 개념과 비교

DaemonSet 예시 (로깅 에이전트)

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: fluentd-elasticsearch
  namespace: kube-system
  labels:
    k8s-app: fluentd-logging
spec:
  selector:
    matchLabels:
      name: fluentd-elasticsearch
  template:
    metadata:
      labels:
        name: fluentd-elasticsearch
    spec:
      tolerations:
      # 컨트롤 플레인 노드에도 배포할 수 있도록 설정
      - key: node-role.kubernetes.io/control-plane
        operator: Exists
        effect: NoSchedule
      containers:
      - name: fluentd-elasticsearch
        image: quay.io/fluentd_elasticsearch/fluentd:v2.5.2
        resources:
          limits:
            memory: 200Mi
          requests:
            cpu: 100m
            memory: 200Mi
        volumeMounts:
        - name: varlog
          mountPath: /var/log
        - name: varlibdockercontainers
          mountPath: /var/lib/docker/containers
          readOnly: true
      terminationGracePeriodSeconds: 30
      volumes:
      - name: varlog
        hostPath:
          path: /var/log
      - name: varlibdockercontainers
        hostPath:
          path: /var/lib/docker/containers

특정 노드에만 배포하기 (노드 선택기)

spec:
  template:
    spec:
      nodeSelector:
        disk: ssd

DaemonSet 업데이트 전략

spec:
  updateStrategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1

일반적인 사용 사례

명령적 방식 관리

# DaemonSet 생성
kubectl create -f daemonset.yaml

# DaemonSet 목록 조회
kubectl get daemonsets -n kube-system

# DaemonSet의 Pod 조회
kubectl get pods -l name=fluentd-elasticsearch -n kube-system

# DaemonSet 업데이트
kubectl apply -f updated-daemonset.yaml

# DaemonSet 삭제
kubectl delete daemonset fluentd-elasticsearch -n kube-system