Scheduling in Kubernetes

김현수·2024년 3월 26일

Kubernetes

목록 보기
12/14

Taints & Tolerations

Taints

node에 pod이 scheduling되지 않도록 설정한다. control plane의 master node는 기본적으로 이 설정이 적용되어 있다. Taint의 effect는 다음 3가지가 있다.
NoSchedule: Schedule 제한
PreferNoSchedule: Schedule 안하도록 권장
NoExecute: 이미 Schedule되었을 경우 preemption

다음과 같이 taint를 추가할 수 있다.

kubectl taint nodes node1 key1=value1:NoSchedule

그리고 다음과 같이 taint를 제거할 수 있다.

kubectl taint nodes node1 key1=value1:NoSchedule-

Tolerations

node의 taint를 무시하고 scheduling되도록 설정한다. Taint의 operator는 다음과 같이 2개가 있다.
Equal: key, value가 겹칠 경우 적용
Exist: key가 겹칠 경우 적용
특수한 케이스로 Exist에 키가 비어있을 경우 모든 Taint를 무시한다.

다음과 같이 toleration을 추가할 수 있다.

tolerations:
- key: "key1"
  operator: "Equal"
  value: "value1"
  effect: "NoSchedule"

Node affinity

taint와 반대로 pod을 해당 node에 배치하도록 한다.

다음과 같이 하면 조건을 만족하는 node에만 스케줄링된다.

apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: disktype
            operator: In
            values:
            - ssd            
  containers:
  - name: nginx
    image: nginx
    imagePullPolicy: IfNotPresent

필드 설명은 다음과 같다.
requiredDuringScheduling: pod이 node에 반드시 배치되어야 한다.
...IgnoredDuringExecution: 이미 실행되고 있는 pod의 경우 pre-emption하지 않는다.
nodeSelectorTerms: affinity의 조건을 지정한다. 여기서는 ssd를 사용하는 label을 선호한다는 뜻이다.

다음과 같이 하면 조건을 만족하는 node에 우선순위를 높인다.

apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  affinity:
    nodeAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 1
        preference:
          matchExpressions:
          - key: disktype
            operator: In
            values:
            - ssd          
  containers:
  - name: nginx
    image: nginx
    imagePullPolicy: IfNotPresent

필드 설명은 다음과 같다.
preferredDuringScheduling...: pod이 node에 배치되도록 권장한다.
preference: affinity의 조건을 지정한다.

또한 weight를 지정할 수 있는데, 여러 조건들이 있을 때 우선순위 반영 비율을 정하는 것이다.

Node anti-affinity

반대로 pod이 해당 node에 선호되지 않도록 할 수 있다. Taint와의 차이점은, pod이 현재 배치되어 있는 정보도 고려할 수 있다. 예를 들어 이미 같은 pod이 들어간 node에 scheduling되지 않도록 권장할 수 있다.

podAntiAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 100
        podAffinityTerm:
          labelSelector:
            matchExpressions:
            - key: security
              operator: In
              values:
              - S2
          topologyKey: topology.kubernetes.io/zone

 

출처

https://kubernetes.io/ko/docs/concepts/scheduling-eviction/taint-and-toleration/#%EC%BB%A8%EB%94%94%EC%85%98-condition-%EC%9D%84-%EA%B8%B0%EC%A4%80%EC%9C%BC%EB%A1%9C-%EB%85%B8%EB%93%9C-%ED%85%8C%EC%9D%B8%ED%8A%B8%ED%95%98%EA%B8%B0

https://kubernetes.io/ko/docs/tasks/configure-pod-container/assign-pods-nodes-using-node-affinity/

https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#inter-pod-affinity-and-anti-affinity

profile
개발자 스터디 블로그

0개의 댓글