CKA (Certified Kubernetes Administrator)/Kode Kloud

02.Scheduling - Labels and Selectors

seulseul 2022. 1. 19. 13:27

LABS – CERTIFIED KUBERNETES ADMINISTRATOR WITH PRACTICE TESTS > SCHEDULING

Scheduling

01. We have deployed a number of PODs.

They are labelled with tier, env and bu. How many PODs exist in the dev environment?

Use selectors to filter the output

답 : 7

controlplane ~ ➜  kubectl get pods --selector env=dev
NAME          READY   STATUS    RESTARTS   AGE
app-1-sxsm5   1/1     Running   0          3m35s
db-1-dl92j    1/1     Running   0          3m35s
db-1-2lsxk    1/1     Running   0          3m35s
db-1-nvtdh    1/1     Running   0          3m35s
db-1-vnk9z    1/1     Running   0          3m35s
app-1-cxdff   1/1     Running   0          3m35s
app-1-9x6kj   1/1     Running   0          3m35s

02. How many PODs are in the finance business unit (bu)?

답 : 6개

kubectl get pods --selector bu=finance

NAME          READY   STATUS    RESTARTS   AGE
app-1-sxsm5   1/1     Running   0          8m42s
auth          1/1     Running   0          8m42s
db-2-z5nwg    1/1     Running   0          8m42s
app-1-zzxdf   1/1     Running   0          8m41s
app-1-cxdff   1/1     Running   0          8m42s
app-1-9x6kj   1/1     Running   0          8m42s

03. How many objects are in the prod environment including PODs, ReplicaSets and any other objects?

답 : 7

controlplane ~ ✖ kubectl get all --selector env=prod
NAME              READY   STATUS    RESTARTS   AGE
pod/auth          1/1     Running   0          10m
pod/db-2-z5nwg    1/1     Running   0          10m
pod/app-1-zzxdf   1/1     Running   0          10m
pod/app-2-knq7t   1/1     Running   0          10m

NAME            TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
service/app-1   ClusterIP   10.43.245.133   <none>        3306/TCP   10m

NAME                    DESIRED   CURRENT   READY   AGE
replicaset.apps/db-2    1         1         1       10m
replicaset.apps/app-2   1         1         1       10m

04. Identify the POD which is part of the prod environment, the finance BU and of frontend tier?

답 : pod/app-1-zzxdf

kubectl get all --selector env=prod,bu=finance,tier=frontend

NAME              READY   STATUS    RESTARTS   AGE
pod/app-1-zzxdf   1/1     Running   0          17m

05. A ReplicaSet definition file is given replicaset-definition-1.yaml.

Try to create the replicaset. There is an issue with the file. Try to fix it.

  • ReplicaSet: replicaset-1
  • Replicas: 2
controlplane ~ ➜  kubectl create -f replicaset-definition-1.yaml 
The ReplicaSet "replicaset-1" is invalid: spec.template.metadata.labels: Invalid value: map[string]string{"tier":"nginx"}: `selector` does not match template `labels`
apiVersion: apps/v1
kind: ReplicaSet
metadata:
   name: replicaset-1
spec:
   replicas: 2
   selector:
      matchLabels:
        tier: frontend
   template:
     metadata:
       labels:
        tier: nginx # frontend 로 수정
     spec:
       containers:
       - name: nginx
         image: nginx

# bookmark

https://kubernetes.io/ko/docs/concepts/overview/working-with-objects/labels/

 

레이블과 셀렉터

레이블 은 파드와 같은 오브젝트에 첨부된 키와 값의 쌍이다. 레이블은 오브젝트의 특성을 식별하는 데 사용되어 사용자에게 중요하지만, 코어 시스템에 직접적인 의미는 없다. 레이블로 오브

kubernetes.io