반응형

용량이 큰 Node1과 나머지 Node 2, 3이 있다.

그리고 많은 자원을 요구하는 pod와 적당한 pod 2개가 있다.

많은 자원을 요구하는 pod가 Node 1에 할당되게 하려면 어떻게 해야할까?

 

pod에 nodeSelector 라는 key를 추가해서, 원하는 node에 해당 pod가 생성되게끔 설정을 해준다.

(size: Large로 명시했음)

* 단, Node 1은 미리 size: Large 라는 value를 가지고 있어야 한다.

 

그래서, Node1에 해당 label 속성을 주기 위해 아래와 같은 명령어를 통해 label을 추가한다.

# kubectl label nodes <node-name> <label-key>=<label-value>
ex. kubectl label nodes node-1 size=Large
ex. kubectl label namespace <namespace> <label-key>=<label-value>

 

 

그리고 다시 'nodeSlelector'를 추가한 pod를 생성하면, Node-1에 원하던 pod가 생성된다.

그런데... 조건이 훨씬 복잡해진다면? (현재 조건은 1개 뿐이다. size:Large)

 

 

 

Node Affinity 라는 게 나온다. 

Node Affinity란? 여러 개의 조건을 사용하여 원하는 Node에 pod를 생성하기 위한 설정이다.

 

 

 

예를들어, nodeSelector는 key가 단순히 label을 비교하는 하나 였다면,

Node Affinity는 'requredDuringSchedulingIgnoredDuringExecution, match Exporessions' 등 여러 가지 조건이 있다.

 

 

 

내용은 생각보다 간단하다.

- requiredDuringSchedulingIgnoredDuringExecution

   : Scheduling 동안 해당 affinity 설정을 가진 node가 없다면 pod를 생성하지 않는다(=required) 

     && pod가 이미 생성된 상태에서 affinity나 label 설정들이 바뀐다면 이를 무시한다(=ignored). (pod는 정상 동작)

- preferredDuringSchedulingIgnoredDuringExecution

   : Scheduling 동안 해당 affinity 설정을 가진 node가 없다면 적당한 곳에 pod를 생성한다(=preferred) 

     && pod가 이미 생성된 상태에서 affinity나 label 설정들이 바뀐다면 이를 무시한다(=ignored). (pod는 정상 동작)

- requiredDuringSchedulingRequiredDuringExecution

   : Scheduling 동안 해당 affinity 설정을 가진 node가 없다면 pod를 생성하지 않는다(=required) 

     && pod가 이미 생성된 상태에서 affinity나 label 설정들이 바뀐다면 이를 반영한다. (pod가 삭제될 수도 있음)

 

 

 

그러면..

이전에 배웠던 Taint & Tolerance와 Node Affinity 차이는 무엇일까?

 

- Taint: Node에 설정해서, 해당 노드에 아무 pod나 생성되지 않게 한다.

- Tolerance: Pod에 설정해서, 해당 pod가 특정 node에"도" 생성될 수 있게 한다. (회색과 같은 다른 node에"도" 생성될 수 있다.)

- Node Affinity: 특정 pod는 특정 node에만 생성될 수 있게 한다! (아래 그림 참고)

 

 

출처: Udemy 사이트의 Certified Kubernetes Administrator (CKA) with Practice Tests 강의

반응형

+ Recent posts