Scheduling & Resource Management
Pod를 어디에 배치하고, 리소스를 어떻게 스케일링할 것인가
1. kube-scheduler 동작
flowchart LR
Pending["Pending Pod"] --> Filter["필터링<br/>(부적합 노드 제거)"]
Filter --> Score["스코어링<br/>(적합 노드 순위)"]
Score --> Bind["바인딩<br/>(최고 점수 노드)"]
| 단계 | 예시 |
|---|---|
| 필터링 | 리소스 부족, Taint 불일치, nodeSelector 불일치 → 제거 |
| 스코어링 | 리소스 여유, Affinity 일치, 균등 분산 → 점수 |
2. 노드 선택
2.1 nodeSelector (간단)
spec:
nodeSelector:
disktype: ssd # 이 레이블을 가진 노드에만 배치
2.2 Node Affinity (유연)
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution: # 필수
nodeSelectorTerms:
- matchExpressions:
- key: zone
operator: In
values: ["zone-a", "zone-b"]
preferredDuringSchedulingIgnoredDuringExecution: # 선호 (노력)
- weight: 1
preference:
matchExpressions:
- key: gpu
operator: Exists
2.3 Pod Affinity / Anti-Affinity
# 같은 노드에 함께 (Affinity)
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchLabels:
app: cache
topologyKey: kubernetes.io/hostname
# 같은 노드에 놓지 않기 (Anti-Affinity) — HA 패턴
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchLabels:
app: db
topologyKey: kubernetes.io/hostname
3. Taint & Toleration
노드에 Taint(오염)를 설정하면, 해당 Taint를 Tolerate(허용)하는 Pod만 스케줄링됨.
# 노드에 Taint 추가
kubectl taint nodes gpu-node gpu=true:NoSchedule
# Taint 제거
kubectl taint nodes gpu-node gpu=true:NoSchedule-
# Pod에 Toleration 추가
tolerations:
- key: "gpu"
operator: "Equal"
value: "true"
effect: "NoSchedule"
| Effect | 동작 |
|---|---|
| NoSchedule | 새 Pod 스케줄링 거부 (기존 Pod 유지) |
| PreferNoSchedule | 가능하면 스케줄링 안 함 (강제는 아님) |
| NoExecute | 새 Pod 거부 + 기존 Pod도 축출 |
활용 패턴:
- Master 노드:
node-role.kubernetes.io/control-plane:NoSchedule(기본) - GPU 전용 노드: 일반 Pod 제외, GPU 워크로드만 허용
- 유지보수 노드:
NoExecute로 모든 Pod 축출
4. 오토스케일링
4.1 HPA (Horizontal Pod Autoscaler)
CPU/메모리 사용률에 따라 Pod 수를 자동 조절.
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: web-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: web
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70 # CPU 70% 넘으면 스케일 아웃
Metrics Server 설치 필수.
kubectl top명령도 Metrics Server가 필요함.
4.2 VPA (Vertical Pod Autoscaler)
Pod의 requests/limits를 자동 조절. Pod 재시작이 필요하므로 HPA보다 덜 사용됨.
4.3 Cluster Autoscaler
노드 수를 자동 조절. Pod가 스케줄링 실패(리소스 부족)하면 노드를 추가하고, 사용률이 낮으면 노드를 제거.
| HPA | VPA | Cluster Autoscaler | |
|---|---|---|---|
| 스케일 대상 | Pod 수 | Pod 리소스 | 노드 수 |
| 방향 | 수평 | 수직 | 수평 (인프라) |
| 재시작 | ❌ 불필요 | ✅ 필요 | — |
| 환경 | 모든 환경 | 모든 환경 | 클라우드 주로 |
5. Priority & Preemption
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
name: high-priority
value: 1000000
globalDefault: false
description: "높은 우선순위 워크로드"
---
spec:
priorityClassName: high-priority
리소스 부족 시 낮은 우선순위 Pod를 축출(Preemption)하여 높은 우선순위 Pod에 자리를 내줌.
다음 글
→ #9 Observability — 로깅 & 모니터링