STUDY/Data Engineering

[kodekloud] 02 Scheduling : Static Pods 풀이 (😵‍💫)

wonpick 2023. 1. 23. 18:43
Q1. How many static pods exist in this cluster in all namespaces?

 Static pod는 controlplane 노드에 생성되기 때문에, grep 을 통해 controlplane을 조회

kubectl get pods --all-namespaces | grep "\-controlplane"

# kube-system 네임스페이스에 있는 pod count 개수
kubectl get pods -n kube-system | wc -l

Q2. Which of the below components is NOT deployed as a static pod?

>> coredns

 

Q3. Which of the below components is NOT deployed as a static POD?

>> kube-proxy

Q4. On which nodes are the static pods created currently?
 k get nodes 
 k get pods --all-namespaces -o wide

Q5. What is the path of the directory holding the static pod definition files?

 

Q6. How many pod definition files are present in the manifests directory?

 

Q7. What is the docker image used to deploy the kube-api server as a static pod?

 

Q8. Create a static pod named static-busybox that uses the busybox image and the command sleep 1000
# . --dry-run, -o yaml 옵션 조합으로 실제 Pod를 생성하지 않고 template을 생성할 수 있다.
kubectl run --restart=Never --image=busybox static-busybox --dry-run=client -o yaml --command -- sleep 1000 > /etc/kubernetes/manifests/static-busybox.yaml

  • apiVersion: 이름 conflict를 방지하기 위해 apiVersion을 명시함으로써, scope를 정의합니다. java의 package와 비슷한 역할을 합니다.
  • kind: 리소스의 타입을 정의합니다. java의 class 이름과 비슷한 역할을 합니다.
  • metadata: 리소스의 메타 정보를 나타냅니다.
    • label: 리소스의 라벨정보를 표기합니다.
    • name: 리소스의 이름을 표기합니다.
  • spec: 리소스를 정의합니다. (description) 여기서부터 리소스마다 조금씩 상이합니다.
    • restartPolicy: 재시작 정책을 지정합니다. (Always, OnFailure, Never가 있습니다.)
    • containers: 한개 이상의 컨테이너를 정의합니다. 예시에는 한개 컨테이너만 존재합니다.
      • name: 컨테이너의 이름을 표기합니다.
      • image: 컨테이너의 이미지를 표기합니다.

Restart Policy(재시작 정책)

  • Always: 항상 재시작합니다. (종료 시 + 에러 발생 시) 웹 서버와 같이 항상 떠있는 데몬 형태의 컨테이너에 적합합니다. (Pod 리소스 기본값)
  • OnFailure: 실패 시에만 재시작합니다. (에러 발생 시) 기계학습과 같이 배치 작업에 적합합니다. (뒤에서 살펴 볼 Job 리소스 기본값)
  • Never: 재시작하지 않습니다. 멱등성이 보장되지 않는 작업이 적합합니다. (멱등성이란, 동일한 연산을 반복하여 적용하여도 동일한 결과가 나오는 성질)

 

Q9. Edit the image on the static pod to use busybox:1.28.4

Q10. We just created a new static pod named static-greenbox. Find it and delete it.
This question is a bit tricky. But if you use the knowledge you gained in the previous questions in this lab, you should be able to find the answer to it.
k get pods --all-namespaces -o wide | grep static-greenbox
ssh node01
ps -ef |  grep /usr/bin/kubelet
grep -i staticpod /var/lib/kubelet/config.yaml
cd /etc/just-to-mess-with-you
rm -rf greenbox.yaml #(logout :ctrl+D)

 
kubectl get pods -o wide
kubectl delete pods static-greenbox-node01
ls /etc/kubernetes/manifests/   
kubectl get nodes -o wide
ssh 10.24.105.9
cat /var/lib/kubelet/config.yaml # grep staticPodPath /var/lib/kubelet/config.yaml
cd /etc/just-to-mess-with-you # node01 $ rm -rf /etc/just-to-mess-with-you/greenbox.yaml
ls 
rm greenbox.yaml
exit
kubectl get pods --watch


참고

1. 파드 살펴보기 - hongkunyoo/docker-k8s-workshop