Node Schedule
kubernetes 배포가 더 크고 다양해지면 스케줄링 관리가 더욱 더 중요하다.
kube-scheduler가 Pod가 할당 될 Node를 결정하는 것을 의미한다.
- nodeSelector : kube-scheduler에게 지정 Node 배치 요청
- nodeName : 해당 Node의 kublet에게 직접 요청
- Affinitiy : 다양한 조건으로 Node 배치 요청
- Tolerations : Taint가 설정된 Node 강제 허용 요청
- schedulerName : Multi Cluster 환경인 경우
Node Label 확인
kubectl get nodes --show-labels
NAME STATUS ROLES AGE VERSION LABELS
k8s-master Ready control-plane 8d v1.28.4 kubernetes.io/hostname=k8s-master,...
k8s-node1 Ready <none> 8d v1.28.4 kubernetes.io/hostname=k8s-node1,...
k8s-node2 Ready <none> 8d v1.28.4 kubernetes.io/hostname=k8s-node2,...
nodeSelector 사용
YAML 파일 생성
kubectl run sch-test1 --image=nginx:1.25.3 --dry-run=client -o yaml > sch-test1.yaml
nodeSelector 추가
- Node Label kubernetes.io/hostname=k8s-node1에 맞춰 설정.
apiVersion: v1
kind: Pod
metadata:
name: sch-test1
spec:
nodeSelector:
kubernetes.io/hostname: k8s-node1
containers:
- image: nginx:1.25.3
name: sch-test1
Pod 배포 및 상태 확인
kubectl apply -f sch-test1.yaml
kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE
sch-test1 1/1 Running 0 30s 10.111.156.120 k8s-node1
Node Label 추가 및 Overwrite
# Label 추가
kubectl label nodes k8s-node2 cputype=gpu
# Label 확인
kubectl get nodes k8s-node2 --show-labels
# Label 수정 (Overwrite)
kubectl label nodes k8s-node2 cputype=gpu2 --overwrite
# Label 삭제
kubectl label nodes k8s-node2 cputype-
nodeName 사용
Pod YAML 수정
apiVersion: v1
kind: Pod
metadata:
name: sch-test3
spec:
nodeName: k8s-node3
containers:
- image: nginx:1.25.3
name: sch-test3
Pod 배포 및 상태 확인
kubectl apply -f sch-test3.yaml
kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE
sch-test3 1/1 Running 0 13s 10.111.218.99 k8s-node3
Taint와 Toleration
Taint와 Toleration은 Kubernetes의 Pod 스케줄링 정책에서 특정 Node에 제한을 두거나, 특정 Pod가 제한을 무시할 수 있도록 설정하는 데 사용된다.
- Taint: 특정 Node에 "제약 조건"을 설정한다. 설정된 Taint는 해당 조건을 허용하지 않는 Pod의 스케줄링을 방지한다.
- Toleration: Pod가 Taint 조건을 "무시"할 수 있도록 허용한다.
Taint 설정
kubectl taint node k8s-node1 cputype=gpu:NoSchedule
Toleration 추가 Pod YAML에 tolerations 필드 추가
apiVersion: v1
kind: Pod
metadata:
name: sch-test4
spec:
tolerations:
- key: "cputype"
operator: "Equal"
value: "gpu"
effect: "NoSchedule"
containers:
- image: nginx:1.25.3
name: sch-test4
Taint 해제
kubectl taint node k8s-node1 cputype=gpu:NoSchedule-'kubernetes' 카테고리의 다른 글
| [kubernetes] Service & Ingress (0) | 2024.12.03 |
|---|---|
| [Kubernetes] Pod Lifecycle(Probe) (0) | 2024.12.03 |
| [Kubernetes] Label, Select & Annotation (0) | 2024.12.03 |
| [Kubernetes] Namespace (0) | 2024.11.29 |
| [Kubernetes] Kubernetes Objects (0) | 2024.11.28 |