1️⃣ 개요
DaemonSet은 기본적으로 클러스터의 모든 노드에서 Pod를 실행하지만, 상황에 따라 특정 노드에만 DaemonSet을 제한적으로 배포해야 할 때가 있습니다.
예를 들어, 모니터링 전용 노드나 GPU 노드, 특정 지역(zone)에 속한 노드에만 에이전트를 설치하고 싶은 경우입니다.
이번 글에서는 DaemonSet을 특정 노드에만 실행하도록 제어하는 방법을 정리합니다.
2️⃣ 활용 가능한 주요 설정 방식 요약
방법 | 주요 설정 키 | 특징 |
Node Selector | nodeSelector | 단순 라벨 기반 매칭 (정확한 라벨 필요) |
Node Affinity | affinity.nodeAffinity | 라벨 기반 조건식 작성 가능 (복잡한 조건 설정 가능) |
Taints & Tolerations | taints + tolerations | 노드에 Taint를 주고, 허용된 Pod만 스케줄링 |
각 설정은 함께 사용하여 제어 범위를 좁힐 수 있으며, 상황에 따라 조합하는 것이 유리합니다.
3️⃣ Node Selector를 사용한 DaemonSet 노드 제어
✅ 1. 노드에 라벨 부여
kubectl label node node-1 dedicated=monitoring
📌 설명
• node-1 노드에 dedicated=monitoring 라벨을 부여합니다.
• 이 라벨은 DaemonSet에서 nodeSelector로 매칭될 조건이 됩니다.
✅ 2. DaemonSet 설정에 nodeSelector 추가
spec:
template:
spec:
nodeSelector:
dedicated: monitoring # 위에서 설정한 노드 라벨과 정확히 일치해야 함
📌 설명
• 이 설정이 포함된 DaemonSet은 dedicated=monitoring 라벨이 있는 노드에만 Pod를 배포합니다.
• 라벨이 없는 노드에는 배포되지 않습니다.
4️⃣ Node Affinity를 사용한 보다 유연한 제어
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- node-1
- node-2
📌 설명
• kubernetes.io/hostname은 노드의 고유 이름을 의미하며, 여러 노드 중 선택적으로 배포할 수 있습니다.
• matchExpressions를 사용하면 In, NotIn, Exists 등의 조건을 활용해 유연한 제어가 가능합니다.
• 위 예시는 node-1, node-2에서만 DaemonSet Pod가 배포되도록 설정합니다.
✅ Node Affinity는 라벨 기반의 정교한 조건식을 작성할 수 있다는 장점이 있습니다.
5️⃣ Taints와 Tolerations를 활용한 강제 제어
✅ 1. 특정 노드에 Taint 적용
kubectl taint nodes node-3 dedicated=monitoring:NoSchedule
📌 설명
• node-3 노드에 NoSchedule Taint를 적용하여, 아무 Pod도 해당 노드에 배포되지 않도록 차단합니다.
• 단, 이 Taint를 toleration으로 허용한 Pod만 배포가 가능해집니다.
✅ 2. DaemonSet에 Tolerations 추가
spec:
template:
spec:
tolerations:
- key: "dedicated"
operator: "Equal"
value: "monitoring"
effect: "NoSchedule"
📌 설명
• 위 설정을 통해 dedicated=monitoring이라는 Taint를 가진 노드에도 이 DaemonSet이 배포될 수 있도록 허용합니다.
• Taint로 일반 Pod를 막고, 허용된 DaemonSet만 실행하도록 제어할 수 있습니다.
✅ Taints & Tolerations는 클러스터 내 특별한 노드를 분리하여 관리하고자 할 때 매우 유용합니다.
6️⃣ DaemonSet 노드 제어 예제 전체 구성
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: custom-agent
spec:
selector:
matchLabels:
app: custom-agent
template:
metadata:
labels:
app: custom-agent
spec:
nodeSelector:
dedicated: monitoring # Node Selector로 라벨 필터링
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- node-1 # 노드 이름 기준으로 필터링
tolerations:
- key: "dedicated"
operator: "Equal"
value: "monitoring"
effect: "NoSchedule" # Taint가 있는 노드에 배포 허용
containers:
- name: custom-agent
image: busybox
command: ["sh", "-c", "while true; do echo Hello from custom agent; sleep 60; done"]
📌 요약 설명
• nodeSelector, nodeAffinity, tolerations을 함께 사용하여 노드 조건을 복합적으로 제한합니다.
• 이 예제는 node-1에만 DaemonSet이 배포되고, 해당 노드에 Taint가 있어도 허용되도록 설정되었습니다.
🔥 7️⃣ 결론
✔ DaemonSet은 기본적으로 모든 노드에 배포되지만, 설정을 통해 특정 노드에만 실행되도록 제어할 수 있습니다.
✔ Node Selector는 단순하고 직관적인 제어 방식이며, Node Affinity는 복잡한 조건 설정에 적합합니다.
✔ Taints & Tolerations를 활용하면 선택된 Pod만 특정 노드에 배포되도록 제어할 수 있습니다.
✔ 이러한 설정을 조합하면 다양한 노드 환경에서 DaemonSet을 유연하게 배포할 수 있습니다.
'Kubernetes > Kubernetes Advanced' 카테고리의 다른 글
📌 [DaemonSet 심화편 #5] DaemonSet과 Host 네트워크 및 호스트 경로 마운트 구성 (0) | 2025.03.21 |
---|---|
📌 [DaemonSet 심화편 #4] DaemonSet Pod 재시작 전략과 장애 복구 패턴 (0) | 2025.03.21 |
📌 [DaemonSet 심화편 #2] DaemonSet 업데이트 전략과 무중단 롤링 배포 적용 (0) | 2025.03.21 |
📌 [DaemonSet 심화편 #1] DaemonSet의 개념과 일반적인 활용 사례 (0) | 2025.03.21 |
📌 [StatefulSet 심화편 #21] StatefulSet과 Horizontal Pod Autoscaler(HPA) 적용 방법 (0) | 2025.03.15 |