[CKA] Scheduler(1)- 노드에 파드 배정하기, labels, selector, taints, toleration

Han·2024년 1월 15일

Udemy_CKA

목록 보기
3/6

💡Scheduler란?

  • 적절한 노드에 파드를 배정하는 것
  • kube-system에 있음
  • 파드의 리소스 요구 사항, 노드의 가용성, 애플리케이션 간의 간섭 등을 고려하여 결정

🐢 기초

pod가 pending 상태일 때, kube-system에 scheduler가 있는지 확인해보기

$ kubectl get pod -n kube-system
NAME                                   READY   STATUS    RESTARTS   AGE
coredns-5d78c9869d-8jd7n               1/1     Running   0          4m38s
coredns-5d78c9869d-kxn2d               1/1     Running   0          4m38s
etcd-controlplane                      1/1     Running   0          4m54s
kube-apiserver-controlplane            1/1     Running   0          4m48s
kube-controller-manager-controlplane   1/1     Running   0          4m50s
kube-proxy-jbh9p                       1/1     Running   0          4m21s
kube-proxy-q9hk4                       1/1     Running   0          4m38s
kube-scheduler-controlplane            1/1     Running   0          20m #스케줄러가 있어야 함

특정 노드에 pod 배정하기

#vi에디터로 수정
$ vi nginx.yaml
---
apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  nodeName: node01 #배정하고 싶은 노드 입력
  containers:
  -  image: nginx
     name: nginx
     
 #이후 파드 재시작
 $ kubectl replace --force -f nginx.yaml #강제로 시작
 
 $ kubectl delete nginx.yaml #혹은 지웠다 재시작
 $ kubectl apply -f nginx.yaml

노드를 변경했을 경우

# vi에디터 통해 수정 후, 파드 재시작 필수
 $ kubectl replace --force -f nginx.yaml #강제로 시작
 
 $ kubectl delete nginx.yaml #혹은 지웠다 재시작
 $ kubectl apply -f nginx.yaml

특정 selector에 있는 pod 조회하기

$ kubectl get pods --selector env=dev
NAME          READY   STATUS    RESTARTS   AGE
app-1-qfc8l   1/1     Running   0          80s
app-1-wrbmh   1/1     Running   0          80s
app-1-4ph79   1/1     Running   0          80s
db-1-52m52    1/1     Running   0          80s
db-1-zqbnh    1/1     Running   0          80s
db-1-zs9bn    1/1     Running   0          80s
db-1-rfwzl    1/1     Running   0          80s

Labels and Selectors

Labels이란? 링크텍스트

  • 쿠버네티스 오브젝트를 식별하기 위한 key/value 쌍의 메타정보
  • 쿠버네티스 리소스를 논리적인 그룹으로 나누기 위해 붙이는 이름표[링크텍스트]
#파드와 노드에 라벨 설정 가능
$ kubectl get pods --show-labels
$ kubectl get nodes --show=labels
$ kubectl label pod cmdpod name=order rel=beta
$ kubectl label pod pod-demo name=login --overwrite #이미 설정된 라벨을 바꾸려면 --overwite
$ kubectl label pod cmdpod name- #key값을 name으로 가지는 라벨 삭제

$ kubectl label nodes node1.example.com gpu=true disk=ssd
$ kubectl get nodes -L disk,gpu #해당 키값을 가지는 노드만 출력
NAME                 STATUS   ROLES           AGE    VERSION   DISK   GPU
master.example.com   Ready    control-plane   133d   v1.28.2          
node1.example.com    Ready    <none>          133d   v1.28.2   ssd    true
node22.example.com   Ready    <none>          133d   v1.28.2          true

Selector란?

  • Label을 이용해 쿠버네티스 리소스를 필터링하고 원하는 리소스 집합을 구하기 위한 label query
  • Label을 이용해 쿠버네티스 리소스를 선택하는 방법(Label query)

특정 환경값과 label에 있는 파드 조회하기

  • label query: key=value
$ kubectl get pods --selector env=dev
NAME          READY   STATUS    RESTARTS   AGE
db-1-ttc6d    1/1     Running   0          13s
app-1-wwqdv   1/1     Running   0          13s
db-1-6nslw    1/1     Running   0          13s
db-1-gjfcp    1/1     Running   0          13s
app-1-vhsbs   1/1     Running   0          13s
db-1-47j5t    1/1     Running   0          12s
app-1-g9c6t   1/1     Running   0          13s

#복수 조건일 때는 컴마(,)로 구분
$ kubectl get all --selector env=prod,bu=finance,tier=frontend

Taints and Tolerations

😣 Taint란?

  • 노드에 설정되는 것
  • Taint를 설정한 노드에는 Pod가 생성되지 않음

😇 Toleration이란?

  • 파드에 설정되는 것
  • Taint가 적용된 노드에 배포하기 위해 설정

taint-effect 종류

  • NoSchedule: toleration이 없으면 pod이 스케쥴되지 않음, 기존 실행되던 pod에는 적용 안됨
  • PreferNoSchedule: toleration이 없으면 pod을 스케줄링안하려고 하지만 필수는 아님, 클러스터내에 자원이 부족하거나 하면 taint가 걸려있는 노드에서도 pod이 스케줄링될 수 있음
  • NoExecute: toleration이 없으면 pod이 스케줄되지 않으며 기존에 실행되던 pod도 toleration이 없으면 종료시킴

노드에 Taint 설정되어 있나 확인해보기 (describe)

kubectl describe no node01
Name:               node01
Roles:              <none>
Labels:             beta.kubernetes.io/arch=amd64             
Annotations:        flannel.alpha.coreos.com/backend-data: {"VNI":1,"VtepMAC":"ba:73:91:96:e4:f6"}
CreationTimestamp:  Tue, 16 Jan 2024 00:34:16 -0500
Taints:             <none> #없음

taint 설정하기 (Create a taint on node01 with key of spray, value of mortein and effect of NoSchedule)

$ kubectl taint nodes node01 spray=mortein:NoSchedule
node/node01 tainted

toleration 설정하기

$ kubectl run bee --image=nginx --dry-run=client -o yaml #dry run으로 먼저 확인
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: bee
  name: bee
spec:
  containers:
  - image: nginx
    name: bee
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}
$ kubectl run bee --image=nginx --dry-run=client -o yaml > bee.yaml #야믈파일 생성하여 수정
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: bee
  name: bee
spec:
  containers:
  - image: nginx
    name: bee
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always
  tolerations:
    - key: "spray"
      value: "mortein"
      effect: "NoSchedule"
      operator: "Equal"
status: {}

taint가 설정된 node에 pod를 배포할 시 (Pending오류 발생)

$ kubectl describe pod mosquito
.
.
.
Events:
  Type     Reason            Age   From               Message
  ----     ------            ----  ----               -------
  Warning  FailedScheduling  33s   default-scheduler  0/2 nodes are available: 1 node(s) had untolerated taint {node-role.kubernetes.io/control-plane: }, 1 node(s) had untolerated taint {spray: mortein}. preemption: 0/2 nodes are available: 2 Preemption is not helpful for scheduling..

taint 제거하기

$ kubectl taint nodes controlplane node-role.kubernetes.io/control-plane:NoSchedule-  #마지막에 -만 추가
node/controlplane untainted

0개의 댓글