Node Selector와 Node Affinity는 Pod에 제한을 걸어 특정 노드에만 스케줄링 될 수 있도록 하는 설정임

예시)

  • 만일 클러스터 중에 하나의 노드에 GPU가 장착이 되어 있다면
  • 딥러닝 훈련 Pod는 해당 노드에 스케줄링되어 구동되도록 함

NodeSelector

  • 간단하고, 가볍게 하나의 Pod에 적용시킬 수 있는 설정
  1. Node에 레이블 적용하기

    • kubectl label nodes <node-name> <label-key>=<label-value>
    • 예시) kubectl label nodes node01 size=Large
  2. Pod에도 <label-value> 명시하기. Node에 적용된 Label 과 매칭되어 스케줄링 됨.


# ex) pod-definition.yaml

apiVersion: v1
kind: Pod
metadata:
	name: data-processor
	
spec:
	containers:
		- name: data-processor
			image: data-processor
			
	nodeSelector:
		size: Large   # node 의 selector 따라 매칭
  • NodeSelector의 경우 한가지 label 매칭만 가능하여, 특정 노드를 제외한 다른 노드 모두, 같은 설정은 제한이 있음.
  • OR 또는 NOT 과 같은 조건은 설정이 불가능

→ 이때는 Node Affinity를 사용

Node Affinity


# ex) pod-definition.yaml

apiVersion: v1
kind: Pod
metadata:
	name: data-processor
	
spec:
	containers:
		- name: data-processor
			image: data-processor
			
	affinity:
		nodeAffinity:
			requiredDuringSchedulingIgnoredDuringExecution:
				nodeSelectorTerms:
				- matchExpressions:
						- key: Size
							operator: In
							values:
							- Large
							- Medium

Operator 유형

  • In - values array에 명시된 selector에 해당하면 적용. OR 역할의 operator
  • NotIn - values array에 명시된 selector라면 제외
  • Exists - value와는 무관, 해당 key 를 가지는 node에만 스케줄링

조건 조합에 따른 Node Affinity 유형

  • requiredDuringSchedulingIgnoredDuringExecution

    • required during Scheduling
      • Pod가 생성될 때, 조건이 꼭 부합해야 함
      • 없다면, 생성되지 않음
    • ignore during Execution
      • node label이 변경되어도, 이를 무시하고 Pod는 계속 구동됨
  • preferredDuringSchedulingIgnoredDuringExecution

    • preferred during Scheduling
      • 조건에 부합하는 노드가 없는 경우 명시된 Node Affinity 규칙을 무시함
      • 다른 노드에 스케쥴링 됨
    • ignore during Execution
      • node의 label이 변경되어도, 이를 무시하고 Pod는 계속 구동됨
  • requiredDuringSchdulingRequiredDuringExecution (적용 예정)

    • required during Scheduling
      • Pod가 생성될 때, 조건이 꼭 부합해야 함
      • 없다면, 생성되지 않음
    • required during Execution
      • node의 label이 변경되면, 조건에 부합하지 않게 된 Pod는 퇴출(evicted) 되거나 종료됨

Resource