STUDY/Data Engineering

[kodekloud] 02 Scheduling : Labels and Selectors 풀이

wonpick 2023. 1. 22. 23:42
Q1. We have deployed a number of PODs. They are labelled with tier, env and bu. How many PODs exist in the dev environment (env)?
k get pods --selector env=dev # env가 dev인 파드 불러오기 
k get pods --selector env=dev --no-headers | wc -l #개수 세기

Q2. How many PODs are in the finance business unit (bu)? 
k get pods --selector bu=finance --no-headers | wc -l
'''--no-headers를 하지 않으면 헤더까지 카운팅 되기 때문에 제외해야함'''

Q3. How many objects are in the prod environment including PODs, ReplicaSets and any other objects?
k get all --selector env=prod # 전체 보기
k get all --selector env=prod --no-headers | wc -l

 

Q4. Identify the POD which is part of the prod environment, the finance BU and of frontend tier?
k get pods --selector env=prod,bu=finance,tier=frontend

pod/app-1-zzxdf

Q5. 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.

selector와 labels 가 매칭될 수 있게 수정함.

vi replicaset-definition-1.yaml
k apply -f replicaset-definition-1.yaml #적용

---
apiVersion: apps/v1
kind: ReplicaSet
metadata:
   name: replicaset-1
spec:
   replicas: 2
   selector:
      matchLabels:
        tier: front-end
   template:
     metadata:
       labels:
        tier: front-end
     spec:
       containers:
       - name: nginx
         image: nginx