brunch
매거진 kakao cloud

카카오 클라우드 4탄-11. 쿠버네티스 레이블

by Master Seo

카카오 클라우드 - 레이블 및 테인트 기반의 파드 배포


<1> 인스턴스 그룹 생성하기

<2> 레이블을 이용한 파드 배포하기

<3> 테인트와 톨러레이션을 이용한 파드 배포하기

<4> 참고 사이트



사전작업

쿠버네티스 클러스터 생성

tutorial



노드 풀에 맞는 레이블 및 테인트 값을 설정합니다.

100 k8s.png




<1> 인스턴스 그룹 생성하기


1

노드풀 2개를 만든다.


110 node1.png




120 lable2.png




150 node.png
160 node.png




170 ok.png


2

생성 확인

[root@host-10-0-3-182 ~]# vi kubeconfig-dgame-dev-cl.yaml

[root@host-10-0-3-182 ~]# export KUBE_CONFIG="kubeconfig-dgame-dev-cl.yaml"



[root@host-10-0-3-182 ~]# kubectl --kubeconfig=$KUBE_CONFIG get nodes

NAME STATUS ROLES AGE VERSION

host-10-0-16-20 Ready <none> 9m35s v1.26.6

host-10-0-18-95 Ready <none> 13m v1.26.6

host-10-0-2-124 Ready <none> 9m9s v1.26.6

host-10-0-3-45 Ready <none> 13m v1.26.6

[root@host-10-0-3-182 ~]#



3

[root@host-10-0-3-182 ~]# alias kubectl='kubectl --kubeconfig=$KUBE_CONFIG'





<2> 레이블을 이용한 파드 배포하기



1

label=true 레이블을 가진 노드에 배포될 것을 지정하는 NodeSelector 설정


[root@host-10-0-3-182 ~]# cat <<EOF | kubectl create -f-

> apiVersion: v1

> kind: Pod

> metadata:

> name: ubuntu-pod-label-example

> spec:

> containers:

> - name: ubuntu-container

> image: ubuntu

> command: ["/bin/bash"]

> args: ["-c", "while true; do echo 'Event: Label Pod is Running...'; sleep 10; done"]

> nodeSelector:

> label: "true"

> EOF


pod/ubuntu-pod-label-example created





2

kubectl get pod ubuntu-pod-label-example


[root@host-10-0-3-182 ~]# kubectl get pod ubuntu-pod-label-example

NAME READY STATUS RESTARTS AGE

ubuntu-pod-label-example 1/1 Running 0 31s



3

kubectl get pod ubuntu-pod-label-example -o custom-columns=NODE_NAME:.spec.nodeName


[root@host-10-0-3-182 ~]# kubectl get pod ubuntu-pod-label-example -o custom-columns=NODE_NAME:.spec.nodeName

NODE_NAME

host-10-0-18-95



4

kr-central-2-b에 위치한 노드에 파드를 배치하는 예시



cat <<EOF | kubectl create -f-

apiVersion: v1

kind: Pod

metadata:

name: ubuntu-pod-label-az-b-example

spec:

containers:

- name: ubuntu-container

image: ubuntu

command: ["/bin/bash"]

args: ["-c", "while true; do echo 'Event: Label Pod is Running...'; sleep 10; done"]

nodeSelector:

label: "true"

topology.kubernetes.io/zone: "kr-central-2-b"

EOF



5

kubectl get pod ubuntu-pod-label-az-b-example -o custom-columns=NODE_NAME:.spec.nodeName


[root@host-10-0-3-182 ~]# kubectl get pod ubuntu-pod-label-az-b-example -o custom-columns=NODE_NAME:.spec.nodeName

NODE_NAME

host-10-0-18-95




<3> 테인트와 톨러레이션을 이용한 파드 배포하기



1

tutorial=true:NoSchedule라는 테인트가 적용된 노드 풀에 예제 파드를 배치합니다.

이 테인트는 해당 노드에 적절한 톨러레이션(toleration)을 가진 파드만을 배정하도록 합니다



cat <<EOF | kubectl create -f-

apiVersion: v1

kind: Pod

metadata:

name: ubuntu-pod-toleration-example

spec:

containers:

- name: ubuntu-container

image: ubuntu

command: ["/bin/bash"]

args: ["-c", "while true; do echo 'Event: Tolerations Pod is Running...'; sleep 10; done"]

nodeSelector:

taint: "true"

tolerations:

- key: "tutorial"

operator: "Equal"

value: "true"

effect: "NoSchedule"

EOF



pod/ubuntu-pod-toleration-example created





[root@host-10-0-3-182 ~]# kubectl get pod ubuntu-pod-toleration-example

NAME READY STATUS RESTARTS AGE

ubuntu-pod-toleration-example 0/1 ContainerCreating 0 8s



3

ot@host-10-0-3-182 ~]# kubectl get pod ubuntu-pod-toleration-example -o custom-columns=NODE_NAME:.spec.nodeName

NODE_NAME

host-10-0-2-124




<4> 참고 사이트


참고자료

https://docs.kakaocloud.com/tutorial/kubernetes/k8s-label



https://brunch.co.kr/@topasvga/3651

pod.png

감사합니다.





keyword
매거진의 이전글카카오 클라우드 4탄-10. 쿠베네티스 모니터링