Node Selector는 Pod를 특정 레이블이 있는 노드에 배치하는 가장 간단한 방법
spec:
nodeSelector:
disktype: ssd
gpu-vendor: nvidia
주요 활용 사례:
특징: 레이블 key-value가 정확히 일치하는 노드에만 배치(AND 조건).
복잡한 조건 불가 → Node Affinity로 대체 가능
Node Name은 Pod를 특정 노드 이름에 강제로 배치
spec:
nodeName: kube-node-01
주요 활용 사례:
특징: 스케줄러를 무시하고 지정된 노드에 직접 배치
노드가 다운되면 Pod는 Pending 상태로 남아있어 일반 애플리케이션에는 비추천
Taints는 노드가 특정 Pod를 거부하도록 설정하고, Tolerations는 Pod가 이를 허용
Taint 설정 (Node):
kubectl taint nodes node-01 special-workload=true:NoSchedule
Toleration 설정 (Pod):
spec:
tolerations:
- key: "special-workload"
operator: "Equal"
value: "true"
effect: "NoSchedule"
Taint 효과:
주요 활용 사례:
Node Affinity는 복잡한 조건으로 노드를 선택
required(강제)와 preferred(선호) 두 가지 유형
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: topology.kubernetes.io/zone
operator: In
values:
- antarctica-east1
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 60
preference:
matchExpressions:
- key: disktype
operator: In
values:
- ssd
지원 연산자: In, NotIn, Exists, DoesNotExist, Gt, Lt
주요 활용 사례:
특징: Node Selector보다 유연하며, 복잡한 조건과 가중치 지원.
Pod Affinity는 특정 Pod와 같은 위치에, Anti-Affinity는 다른 위치에 배치
topologyKey로 범위를 지정
spec:
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchLabels:
app: cache-service
topologyKey: "kubernetes.io/hostname"
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchLabels:
app: my-critical-app
topologyKey: "kubernetes.io/hostname"
실제 시나리오 예제: 웹 서버와 Redis를 같은 AZ에 배치
spec:
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchLabels:
app: redis
topologyKey: "topology.kubernetes.io/zone"
주요 활용 사례:
Topology Spread Constraints는 Pod를 노드, AZ, 리전 등에 고르게 분산
spec:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: "topology.kubernetes.io/zone"
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app: my-app
주요 필드:
주요 활용 사례:
특징: Anti-Affinity보다 세밀한 분산 제어 가능.
Kubernetes Pod 스케줄링은 클러스터의 가용성, 성능, 비용 효율성을 최적화하는 핵심 도구
간단한 배치에는 Node Selector와 Node Name을
노드 격리에는 Taints & Tolerations를
복잡한 조건과 관계 제어에는 Node/Pod Affinity를
고른 분산에는 Topology Spread Constraints를 활용
참고 자료: