본문 바로가기
Compute/kubernetis

[따배씨] 8. Node Selector / CKA 시험 문제 학습

by 조청유곽 2025. 1. 30.
반응형

이 포스팅은 아래의 유튜브 채널 "따배"를 따라서 학습한 내용입니다.  

 

 

 

 

[관련 이론]

 

 

Node selector의 용도 

Pod를 생성할 때, node selector를 생성한다.

node selector와 동일한 레이블이 설정된 node에서 pod가 배포된다. 


 

 

[Precondition]

(1) 테스트 환경

(1.1) Rocky Linux Cluster 

: 직접 구성

[root@k8s-master ~]# k get nodes -o wide
NAME         STATUS   ROLES           AGE   VERSION   INTERNAL-IP     EXTERNAL-IP   OS-IMAGE                            KERNEL-VERSION                  CONTAINER-RUNTIME
k8s-master   Ready    control-plane   30d   v1.27.2   192.168.56.30   <none>        Rocky Linux 8.10 (Green Obsidian)   4.18.0-553.33.1.el8_10.x86_64   containerd://1.6.32
k8s-node1    Ready    <none>          30d   v1.27.2   192.168.56.31   <none>        Rocky Linux 8.8 (Green Obsidian)    4.18.0-477.10.1.el8_8.x86_64    containerd://1.6.21
k8s-node2    Ready    <none>          30d   v1.27.2   192.168.56.32   <none>        Rocky Linux 8.8 (Green Obsidian)    4.18.0-477.10.1.el8_8.x86_64    containerd://1.6.21
[root@k8s-master ~]#

 

(1.2) Ubuntu Cluster 

: kodekloud 테스트 환경 활용

controlplane ~ ➜  kubectl get nodes -o wide
NAME           STATUS   ROLES           AGE     VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION   CONTAINER-RUNTIME
controlplane   Ready    control-plane   9m6s    v1.31.0   192.6.94.6    <none>        Ubuntu 22.04.4 LTS   5.4.0-1106-gcp   containerd://1.6.26
node01         Ready    <none>          8m31s   v1.31.0   192.6.94.9    <none>        Ubuntu 22.04.4 LTS   5.4.0-1106-gcp   containerd://1.6.26

https://learn.kodekloud.com/user/courses/udemy-labs-certified-kubernetes-administrator-with-practice-tests

 

 

(2) 사전 필요 설정 

: pod를 배포할 노드에 label을 미리 설정한다. 

controlplane ~ ➜  k get nodes --show-labels 
NAME           STATUS   ROLES           AGE   VERSION   LABELS
controlplane   Ready    control-plane   52m   v1.31.0   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=controlplane,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=,node.kubernetes.io/exclude-from-external-load-balancers=
node01         Ready    <none>          52m   v1.31.0   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node01,kubernetes.io/os=linux

controlplane ~ ➜  

controlplane ~ ➜  k label nodes node01 disktype=ssd
node/node01 labeled

controlplane ~ ➜  k get nodes --show-labels 
NAME           STATUS   ROLES           AGE   VERSION   LABELS
controlplane   Ready    control-plane   53m   v1.31.0   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=controlplane,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=,node.kubernetes.io/exclude-from-external-load-balancers=
node01         Ready    <none>          52m   v1.31.0   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,disktype=ssd,kubernetes.io/arch=amd64,kubernetes.io/hostname=node01,kubernetes.io/os=linux


 

 

[Question]

k8s

Schedule a pod as follows:
- Name : eshop-store
- Image : nginx
- Node Selector : disktype=ssd

 

 

[Solve]

(1) pod 생성 

controlplane ~ ➜  k run eshop-store --image=nginx --dry-run=client -o yaml > 8-pod.yaml

controlplane ~ ➜  vi 8-pod.yaml 

controlplane ~ ➜  k apply -f 8-pod.yaml 
pod/eshop-store created
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: eshop-store
  name: eshop-store
spec:
  containers:
  - image: nginx
    name: eshop-store
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always
  nodeSelector:
    disktype: ssd
status: {}

 

 

 

(2) 생성한 pod가 node selector가 설정된 node에 배포되었는지 확인  

controlplane ~ ➜  k get pods -o wide
NAME                        READY   STATUS    RESTARTS   AGE   IP            NODE           NOMINATED NODE   READINESS GATES
eshop-store                 1/1     Running   0          12s   172.17.1.10   node01         <none>           <none>
nginx-app-7bf488585-9dnws   1/1     Running   0          33m   172.17.1.9    node01         <none>           <none>
nginx-app-7bf488585-jpp44   1/1     Running   0          33m   172.17.1.8    node01         <none>           <none>
nginx-app-7bf488585-z47tf   1/1     Running   0          33m   172.17.0.8    controlplane   <none>           <none>

 


 

 

[사용 커맨드 정리]

k get nodes --show-labels

k run eshop-store --image=nginx --dry-run=client -o yaml

k run eshop-store --image=nginx --dry-run=client -o yaml > 8-pod.yaml

vi 8-pod.yaml 

k apply -f 8-pod.yaml 

k get pods -o wide

반응형