Node Schedule

dongbin_Shin·2022년 11월 15일
0

kubernetes

목록 보기
3/16

1. 직접 선택하여 할당

Node 생성 시 Label을 등록하고 Pod에 해당 node의 label을 작성

apiVersion: v1
kind: Pod
metadata:
  name: pod-3
spec:
  nodeSelector:
    hostname: node1
  containers:
  - name: container
    image: kube/something

2. 스케쥴러가 판단하여 할당

현재 node들의 남은 자원을 기준으로 판단하여 적절한 Node에 배치

node1의 잉여 메모리: 1Gi
node2의 잉여 메모리: 4Gi
새로운 Pod의 필요 메모리: 2Gi
→ 스케쥴러가 node2에 pod를 배치함

pod 안에 있는 app에 부하가 생길 때 node의 자원을 무한정 사용하려 할 경우 해당 Node의 다른 pod들도 함께 죽을 수 있음

apiVersion: v1
kind: Pod
metadata:
  name: pod-3
spec:
  containers:
  - name: container
    image: kube/something
    resources:
      requests:
        memoty: 2Gi
      limits:
        memory: 3Gi
  • limits
    • Memory: 초과시 pod 종료
    • Cpu: 초과시 request로 낮춤, Over시 종료되지 않음

Scheduling 방식

Node 선택

NodeName

  • node의 이름을 선택하여 배포
  • node의 이름은 변경되므로 비추천되는 방식

NodeSelector

  • node의 label을 선택하여 배포
  • 일치하는 label의 node가 2개 이상일 경우 스케쥴러가 판단하여 더 자원이 많은 node에 배포
  • key, value가 모두 일치해야 배포하고, 하나라도 다를 경우 배포 실패되는 단점

NodeAffinity

  • Node의 label의 key를 선택하여 배포

  • 일치하는 Key의 node 중 스케쥴러가 판단하여 더 자원이 많은 node에 배포

  • 일치하는 Key가 없을 경우 스케쥴러가 판단하여 전체 node 중 가장 자원이 많은 곳에 배포

  • 옵션

    • matchExpressions : 조건을 만족하는 label을 가진 node에 배포

      • Exists
      • DoesNotExist
      • In
      • NotIn
      • Gt
      • Lt
    • required : 지정한 Key와 동일한 node가 없을 경우 배포 x

      apiVersion: v1
       kind: Pod
       metadata:
         name: pod-match-expressions1
       spec:
         affinity:
           nodeAffinity:
             requiredDuringSchedulingIgnoredDuringExecution:
               nodeSelectorTerms:
               - matchExpressions:
                 - {key: kr, operator: Exists}
         containers:
         - name: container
           image: something
    • preferred : 지정한 Key와 동일한 node가 없을 경우에도 스케쥴러가 배포

      apiVersion: v1
       kind: Pod
       metadata:
         name: pod-match-expressions1
       spec:
         affinity:
           nodeAffinity:
             preferredDuringSchedulingIgnoredDuringExecution:
               - weight: 1
                 preference:
                   matchExpressions:
                   - {key: kr, operator: Exists}
         containers:
         - name: container
           image: something
    • preferred weight : 지정한 Key와 동일한 node가 다수일 경우 가중치를 줄 점수

Pod간 집중/분산

Pod Affinity

  • 다수의 Pod가 동일한 node에 배포되어야 할 때 사용
  • podAffinity.matchExpressions 에 찾을 Pod의 key와 expressions를 명시
  • podAffinity를 가진 Pod이 대상 Pod보다 먼저 배포가 되면 Pending 상태로 대상 Pod의 배포를 기다림
  • topologyKey 에 해당하는 node에서만 Pod을 찾음

    예시) 같은 hostpath를 사용하는 다수의 Pod이 있을 경우

    apiVersion: v1
     kind: Pod
     metadata:
       name: server1
     spec:
       affinity:
         podAffinity:
           requiredDuringSchedulingIgnoredDuringExecution:
           - topologyKey: a-team
             labelSelector:
               matchExpressions:
               - {key: type, operator: In, values: [web1]}
       containers:
       - name: container
         image: something

Anti Affinity

  • 다수의 Pod가 서로 다른 node에 배포되어야 할 때 사용
  • podAntiAffinity.matchExpressions 에 찾을 Pod의 key와 expressions를 명시→ 해당 node에 배포 X
  • topologyKey 에 해당하는 node에서만 Pod을 찾음
  • 예시: master, slave 관계인 Pod의 경우
    apiVersion: v1
     kind: Pod
     metadata:
       name: slave
     spec:
       affinity:
         podAntiAffinity:
           requiredDuringSchedulingIgnoredDuringExecution:
           - topologyKey: a-team
             labelSelector:
               matchExpressions:
               - {key: type, operator: In, values: [master]}
       containers:
       - name: container
         image: something

Node에 할당 제한

Toleration / Taint

  • 특정 Node에는 특정 Pod만 배포하고 싶을 경우 사용
  • Taint 설정이 되어 있는 Node에는 Toleration을 달고 있는 Pod만 배포 가능
  • 주의사항
    • Toleration이 있는 Pod도 Taint node가 아닌 다른 node에 배포될 수 있으므로 nodeSelector 옵션으로 Taint node를 선택해주어야 한다.
    • Node에 Taint가 설정돼도 기존에 있던 Pod들은 영향을 받지 않음 → NoExecute로 종료 가능
  • 옵션
    • effect
      • NoSchedule: Taint와 Toleration이 매핑되어야만 배포 가능
      • PreferNoSchedule: 배포 가능한 다른 Node가 없을 경우 Taint가 있는 Node에도 배포 가능
      • NoExecute: 기존에 있던 Pod들도 node의 Taint와 매핑되지 않으면 종료
        • Pod의 Toleration.tolerationSec , Toleration.effect: NoExecute 가 설정되어 있다면 Node에 NoExecute가 걸려도 tolerationSec 이후에 종료
    • operator
      • Equal
      • Exists

$ kubectl taint nodes node1 hw=gpu;NoSchedule

apiVersion: v1
kind: Pod
metadata:
  name: pod-with-toleration
spec:
  nodeSelector:
    gpu: no1
  tolerations:
  - effect: NoSchedule
    key: hw
    operator: Equal
    value: gpu
  containers:
  - name: container
    image: something
profile
멋있는 백엔드 개발자

0개의 댓글