본문 바로가기
CKA

[Udemy CKA - Core Concepts] Node

by 2won2 2024. 8. 23.

 

Node Selectors

  • 특정 Pod가 특정 Node에 host 되도록 함
  • Pod Yaml 파일 spec 아래에 nodeSelector 작성
apiVersion:
kind: Pod
metadata:
  name: myapp-pod
spec:
  containers:
    - name:
      image:
  nodeSelector:
    size: Large
  • 여기에서 size는 label이름
  • kubectl label nodes Node-name label-key=label-value
  • ex) kubectl label nodes node-1 size=Large
  • 한계 : Pod를 중간 Node에 놓거나 하는 것은 불가능

 

Node Affinity

  • 특정 Pod가 특정 Node에 host 되도록 함
  • Pod Yaml 파일 spec 아래에 affinity 작성
apiVersion: v1
kind: Pod
metadata:
  name:
spec:
  containers:
    - name: myapp-container
      image: myapp-image
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:          
         nodeSelectorTerms:
            - matchExpressions:
              - key: size
                operator: In
                values:
                  - Large

 

  • operator에 들어가는 값
    • In : label key 값이 values 리스트 중 하나와 일치할 때
      • ex) key: size, operator: In, values: ["Large", "Medium"]인 경우, Node의 size label이 Large나 Medium 중 하나일 때 조건 만족
    • NotIn : label key 값이 values 리스트에 포함되지 않을 때
      • ex) key: size, operator: NotIn, values: ["Small"]인 경우, Node의 size label이 Small이 아닐 때 조건 만족
    • Exists : label key가 존재하기만 하면 됨
      • ex) key: size, operator: Exists인 경우, Node에 size라는 label key가 있으면 조건 만족
    • DoesNotExist : label key가 존재하지 않을 때
      • ex) key: size, operator: DoesNotExist일 경우, Node에 size라는 label key가 없으면 조건 만족
    • Gt (Greater Than) : label key 값이 values 리스트의 첫 번째 값보다 클 때(숫자형 값에만 적용)
      • ex) key: size, operator: Gt, values: ["3"]인 경우, Node의 size label 값이 3보다 클 때 조건 만족
    • Lt (Less Than): label key 값이 values 리스트의 첫 번째 값보다 작을 때
      • ex) key: size, operator: Lt, values: ["5"]인 경우, Node의 size label 값이 5보다 작을 때 조건 만족

 

 

 

Node Affinity Types

  • requiredDuringSchedulingIgnoredDuringExecution
  • preferredDuringSchedulingIgnoredDuringExecution
    • DuringScheduling : Pod가 존재하지 않다가 처음으로 만들어지는 상태(이후 규칙에 따라 Pod 생성)
      • Required : 일치하는 label을 가진 Node가 없으면 Pod가 생성되지 않음(스케줄링이 안됨)
      • Preferred : 일치하는 label을 가진 Node가 없어도 pod가 스케줄링됨
    • IgnoredDuringExcution : Pod는 계속 실행되고 새로운 Pod에만 해당
  • requiredDuringSchedulingRequiredDuringExecution(예정)
    • Node의 label이 변경되는 경우, Ignored는 이전에 만들어졌던 Pod는 계속 실행되지만, Required는 조건에 맞지 않는 Pod를 쫓아냄

 

 

Practice

  • 노드 node01에 color=blue 라벨을 적용
    • kubectl label node node01 color=blue
  • 어떤 Node에 배치될 수 있는지 확인
    • kubectl describe node를 통해 taint 설정 확인
  • Pod를 오직 node01에만 배치하도록 deployment에 Node Affinity를 설정
    • Node의 label에 color=blue가 있음
    • kubectl edit deploy blue
  • 오직 controlplane 노드에서만 실행되도록 새로운 Deployment를 생성(node-role.kubernetes.io/control-plane 라벨 키 사용)
    • kubectl describe node controlplane 확인
    • node-role.kubernetes.io/control-plane 라벨 키에는 Value 값이 없음