Scheduling-Manual Scheduling
2024. 12. 31. 02:57ㆍ쿠버네티스/쿠버네티스
728x90
반응형
1. Kubernetes 스케줄러와 수동 스케줄링의 필요성
- Kubernetes 스케줄러:
- Kubernetes의 기본 스케줄러는 새로 생성된 Pod 중 nodeName 필드가 설정되지 않은 Pod를 찾아 적절한 노드를 선택.
- 스케줄링 알고리즘을 통해 Pod의 리소스 요구사항(CPU, 메모리 등)과 노드 상태를 고려하여 최적의 노드를 결정.
- 선택된 노드에 nodeName 필드를 설정하고, 이를 API 서버에 전달하여 Pod를 해당 노드에 바인딩.
- 스케줄러가 없는 경우:
- 클러스터에 스케줄러가 없으면, Pod는 Pending 상태로 유지되며 실행되지 않음.
- 이 경우 사용자가 직접 Pod를 특정 노드에 수동으로 스케줄링해야 함.
2. 수동 스케줄링 방법
1) Pod 정의 파일에서 nodeName 필드 설정
- 가장 간단한 방법은 Pod 정의 파일에서 nodeName 필드를 추가하여 특정 노드에 할당하는 것.
- 예시:
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
app: nginx
spec:
containers:
- name: nginx-container
image: nginx
ports:
- containerPort: 8080
nodeName: node02 # Pod를 "node02"에 할당
kubectl apply -f pod.yaml
kubectl get pods -o wide
2) 이미 생성된 Pod를 특정 노드에 바인딩
- 기존 Pod의 nodeName 필드는 수정할 수 없으므로, Binding 객체를 생성하여 특정 노드에 바인딩.
- Binding 객체 예시:
apiVersion: v1
kind: Binding
metadata:
name: nginx # 기존 Pod 이름과 동일해야 함
target:
apiVersion: v1
kind: Node
name: node02 # 타겟 노드 이름
#Binding 객체 적용 명령
kubectl apply -f binding.yaml
# HTTP POST 요청을 통해 바인딩 수행
curl --header "Content-Type: application/json" \
--request POST \
--data '{
"apiVersion": "v1",
"kind": "Binding",
"metadata": {
"name": "nginx"
},
"target": {
"apiVersion": "v1",
"kind": "Node",
"name": "node02"
}
}' http://<API_SERVER>/api/v1/namespaces/default/pods/nginx/binding
주의사항
- nodeName 필드의 한계:
- nodeName은 Pod 생성 시에만 설정 가능하며, 이후에는 변경 불가.
- 지정된 노드가 삭제되거나 사용할 수 없는 경우, Pod는 재스케줄링되지 않음.
- Binding 객체 사용 시 주의:
- Binding은 Kubernetes 기본 스케줄러의 동작을 우회하므로, 클러스터 관리 효율성이 저하될 수 있음.
- 스케줄링 전략 부족:
- nodeName을 사용하는 방식은 단순히 특정 노드에 Pod를 고정할 뿐이며, 리소스 최적화나 고급 스케줄링 정책(예: affinity/anti-affinity)을 지원하지 않음.
test
pod 다른 노드로 옮기기
#기존 Pod 수정 및 재생성
#Pod 정의 파일 수정:
#기존 Pod 정의 파일에 nodeName 필드를 추가하여 Control Plane 노드로 지정.
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx-container
image: nginx
nodeName: control-plane # Control Plane 노드 지정
#기존 Pod를 삭제하고 새롭게 생성.
kubectl delete pod nginx
kubectl apply -f pod.yaml
appply 명령어 대신 replace사용해도 됨
- kubectl replace --force -f nginx.yaml
이 명령어는 다음 작업을 수행:
- 기존 Pod를 강제로 삭제.
- 수정된 정의 파일을 기반으로 새로운 Pod 생성.
반응형
'쿠버네티스 > 쿠버네티스' 카테고리의 다른 글
Scheduling-Taints and Tolerations (0) | 2024.12.31 |
---|---|
Scheduling-Labels and Selectors (0) | 2024.12.31 |
Imperative vs Declarative (0) | 2024.12.31 |
Namespaces (0) | 2024.12.31 |
Kubernetes Deployment (0) | 2024.12.30 |