쿠버네티스 클러스터 생성
tutorial
노드 풀에 맞는 레이블 및 테인트 값을 설정합니다.
1
노드풀 2개를 만든다.
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'
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
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
참고자료
https://docs.kakaocloud.com/tutorial/kubernetes/k8s-label
https://brunch.co.kr/@topasvga/3651
감사합니다.