1. 레이블 : 클라우드 인스턴스를 관리하기 위한 용도
  2. 레이블을 이용하여 조회할때 사용 가능
root@ip-172-31-4-27:~# kubectl get po --all-namespaces --show-labels 
NAMESPACE         NAME                                       READY   STATUS    RESTARTS   AGE     LABELS
calico-system     calico-kube-controllers-5c6f449c6f-w2pwg   1/1     Running   0          6h34m   k8s-app=calico-kube-controllers,pod-template-hash=5c6f449c6f

root@ip-172-31-4-27:~# kubectl get po --all-namespaces -l k8s-app=calico-kube-controllers,pod-template-hash=5c6f449c6f
NAMESPACE       NAME                                       READY   STATUS    RESTARTS   AGE
calico-system   calico-kube-controllers-5c6f449c6f-w2pwg   1/1     Running   0          6h35m

마스터 노드에 레이블 추가 후 pod 생성

root@ip-172-31-4-27:~# kubectl label nodes ip-172-31-4-27 disktype=ssd 
(#@ 마스터 노드에 레이블 추가)
node/ip-172-31-4-27 labeled

root@ip-172-31-4-27:~# vi simple.yml 
kind: Pod
apiVersion: v1
metadata:
  name: mypod
spec:
  containers:
  - image: nginx
    name: hwk
  nodeSelector:
    disktype: ssd

root@ip-172-31-4-27:~# kubectl create -f simple.yml 
pod/mypod created

root@ip-172-31-4-27:~# kubectl get po
NAME                     READY   STATUS    RESTARTS   AGE
mypod                    1/1     Running   0          6s

scale을 이용해 3개를 만들고, 그중 하나의 Lable을 강제로 변경 테스트

어떻게 될 것인가? => Replica Set 의 DESIRED를 충족 시키기 위해 새로운 Pod가 생성 된다.

root@ip-172-31-4-27:~# kubectl create -f template_deploy.yaml 
deployment.apps/example created

root@ip-172-31-4-27:~# kubectl scale deployment example --replicas=3
deployment.apps/example scaled

root@ip-172-31-4-27:~# kubectl get deployments.apps 
NAME      READY   UP-TO-DATE   AVAILABLE   AGE
example   3/3     3            3           26s

3개중에 1개의 레이블을 변경해보자.

root@ip-172-31-4-27:~# kubectl edit po example-c4b46fd7d-96xxd

root@ip-172-31-4-27:~# kubectl get deployments.apps,rs,po -o wide --show-labels 
NAME                      READY   UP-TO-DATE   AVAILABLE   AGE     CONTAINERS   IMAGES   SELECTOR      LABELS
deployment.apps/example   3/3     3            3           4m58s   nginx        nginx    app=example   app=example

레이블명이 달라 RS의 DESIRED 값이 3개 이므로 달라진 녀석 대체로 1개 더 pod를 생성한다.
다시 lable 명을 원복하면 어떻게 될까?
가장 최근에 생성된 pod가 제거가 되고 pod는 3개를 유지한다.

root@ip-172-31-4-27:~# kubectl get deployments.apps,rs,po -o wide --show-labels 
NAME                      READY   UP-TO-DATE   AVAILABLE   AGE    CONTAINERS   IMAGES   SELECTOR      LABELS
deployment.apps/example   3/3     3            3           7m4s   nginx        nginx    app=example   app=example

NAME                                DESIRED   CURRENT   READY   AGE     CONTAINERS   IMAGES   SELECTOR                                  LABELS
replicaset.apps/example-c4b46fd7d   3         3         3       7m4s    nginx        nginx    app=example,pod-template-hash=c4b46fd7d   app=example,pod-template-hash=c4b46fd7d
replicaset.apps/nginx-6799fc88d8    1         1         1       5h34m   nginx        nginx    app=nginx,pod-template-hash=6799fc88d8    app=nginx,pod-template-hash=6799fc88d8

NAME                          READY   STATUS    RESTARTS   AGE     IP               NODE               NOMINATED NODE   READINESS GATES   LABELS
pod/example-c4b46fd7d-96xxd   1/1     Running   0          6m47s   192.168.82.12    ip-172-31-13-180   <none>           <none>            app=example,pod-template-hash=c4b46fd7d
pod/example-c4b46fd7d-9pnwk   1/1     Running   0          7m4s    192.168.82.11    ip-172-31-13-180   <none>           <none>            app=example,pod-template-hash=c4b46fd7d
pod/example-c4b46fd7d-g9mm9   1/1     Running   0          6m47s   192.168.51.199   ip-172-31-4-27     <none>           <none>            app=example,pod-template-hash=c4b46fd7d
pod/mypod                     1/1     Running   0          12m     192.168.51.198   ip-172-31-4-27     <none>           <none>            <none>
pod/nginx-6799fc88d8-v9m2z    1/1     Running   0  

'클라우드 컴퓨팅 & NoSQL > k8s' 카테고리의 다른 글

Deployment와 RollingUpdate 설명  (0) 2020.12.02
ReadinessProbe,LivenessProbe  (0) 2020.12.01
Static Pod  (0) 2020.12.01
Namespace  (0) 2020.12.01
pod 삭제  (0) 2020.12.01

+ Recent posts