
CKA 스케줄링 섹션에서 PriorityClass를 학습했다. 파드 간 우선순위 개념을 잡고, high-priority, batch-low, default-priority 세 가지 PriorityClass를 직접 만들어 파드에 적용하는 실습을 진행했다.
노드 리소스가 부족할 때 어떤 파드를 먼저 배치하고 보호할지 결정하는 값이다.
값이 높을수록 우선순위 높음
system-node-critical 2,000,001,000 ← 시스템 예약
system-cluster-critical 2,000,000,000 ← 시스템 예약
사용자 정의 0 ~ 1,000,000,000
일반 사용자가 만들 수 있는 최댓값은 10억이다. 10억 초과는 쿠버네티스 시스템 컴포넌트용 예약 영역이라 거부된다.
우선순위가 높은 파드가 자리를 못 잡을 때 어떻게 동작할지 결정한다.
| PreemptLowerPriority | Never | |
|---|---|---|
| 기본값 | O | X |
| 낮은 파드 선점 | O (죽이고 자리 차지) | X (대기) |
| 용도 | 중요 서비스 | 배치 작업 |
Never는 우선순위는 높지만 다른 파드를 죽이지 않고 자리가 날 때까지 Pending 상태로 대기한다.
클러스터 기본 PriorityClass를 먼저 확인했다.
kubectl get priorityclass
NAME VALUE GLOBAL-DEFAULT AGE PREEMPTIONPOLICY
system-cluster-critical 2000000000 false 3h20m PreemptLowerPriority
system-node-critical 2000001000 false 3h20m PreemptLowerPriority
실제 시스템 파드에 어떤 클래스가 붙어있는지도 확인했다.
kubectl get pod kube-apiserver-kind-control-plane -n kube-system \
-o jsonpath='{.spec.priorityClassName}'
# system-node-critical
kubectl get pod coredns-7d764666f9-v9mvs -n kube-system \
-o jsonpath='{.spec.priorityClassName}'
# system-cluster-critical
etcd, apiserver, scheduler 등은 system-node-critical, coredns는 system-cluster-critical이 붙어있다. 노드가 죽으면 클러스터도 의미없으니 노드 레벨 컴포넌트를 더 높게 잡은 것이다.
kubectl run으로는 PriorityClass를 직접 지정할 수 없다. dry-run으로 뽑아서 spec.priorityClassName을 추가해야 한다.
kubectl create priorityclass high-priority --value=1000000
kubectl run important --image=nginx --dry-run=client -o yaml > important.yaml
spec:
priorityClassName: high-priority # 추가
containers:
- name: important
image: nginx
kubectl apply -f important.yaml
kubectl get pod important -o jsonpath='{.spec.priorityClassName}'
# high-priority
describe로 Priority 값도 확인할 수 있다.
kubectl describe pods important
# Priority: 1000000
# Priority Class Name: high-priority
배치성 작업용으로 선점 없는 PriorityClass를 만들었다.
kubectl create priorityclass batch-low --value=100 --preemption-policy=Never
kubectl run batch-job --image=busybox --dry-run=client -o yaml \
-- sleep 3600 > batch-job.yaml
# spec.priorityClassName: batch-low 추가 후 apply
kubectl get pods
# NAME READY STATUS RESTARTS
# batch-job 1/1 Running 0
# important 1/1 Running 0
PriorityClass를 지정하지 않은 파드에 자동으로 적용될 기본값을 설정했다.
kubectl create priorityclass default-priority \
--value=1000 \
--global-default=true
kubectl get priorityclass
NAME VALUE GLOBAL-DEFAULT PREEMPTIONPOLICY
batch-low 100 false Never
default-priority 1000 true PreemptLowerPriority
high-priority 1000000 false PreemptLowerPriority
system-cluster-critical 2000000000 false PreemptLowerPriority
system-node-critical 2000001000 false PreemptLowerPriority
globalDefault는 클러스터 전체에 하나만 존재할 수 있다.
| 구분 | 내용 |
|---|---|
| 값 범위 (사용자) | 0 ~ 1,000,000,000 |
| 값 범위 (시스템) | 1,000,000,000 초과 |
| preemptionPolicy 기본값 | PreemptLowerPriority |
| globalDefault | 클러스터당 하나만 가능 |
| 파드에 적용 방법 | spec.priorityClassName |
Q1. PriorityClass high-priority (value: 1000000)를 만들고 nginx 파드 important에 적용하라.
→ kubectl run으로 PriorityClass 직접 지정 불가. dry-run으로 뽑아서 spec.priorityClassName 추가
Q2. PriorityClass batch-low (value: 100, preemptionPolicy: Never)를 만들고 busybox 파드 batch-job에 적용하라.
→ --preemption-policy=Never 옵션, busybox는 -- sleep 3600 추가
Q3. 시스템 파드의 PriorityClass를 확인하고 globalDefault PriorityClass를 생성하라.
→ -o jsonpath='{.spec.priorityClassName}'으로 확인, --global-default=true 옵션