CKA (Certified Kubernetes Administrator)/Kode Kloud

02. Scheduling - Static PODs

seulseul 2022. 1. 20. 13:59

LABS – CERTIFIED KUBERNETES ADMINISTRATOR WITH PRACTICE TESTS > SCHEDULING  STATIC PODS

Scheduling

 

01. How many static pods exist in this cluster in all namespaces?

 

ask :) 4

root@controlplane:~# kubectl get pod --all-namespaces
NAMESPACE     NAME                                   READY   STATUS    RESTARTS   AGE
kube-system   coredns-74ff55c5b-26bjz                1/1     Running   0          15m
kube-system   coredns-74ff55c5b-fkdrx                1/1     Running   0          15m
kube-system   etcd-controlplane                      1/1     Running   0          15m
kube-system   kube-apiserver-controlplane            1/1     Running   0          15m
kube-system   kube-controller-manager-controlplane   1/1     Running   0          15m
kube-system   kube-flannel-ds-5zj78                  1/1     Running   0          15m
kube-system   kube-flannel-ds-zp2gr                  1/1     Running   0          14m
kube-system   kube-proxy-8lptx                       1/1     Running   0          14m
kube-system   kube-proxy-l4ld5                       1/1     Running   0          15m
kube-system   kube-scheduler-controlplane            1/1     Running   0          15m
# Hint

Run the command 
kubectl get pods --all-namespaces 

and look for those with -controlplane appended in the name

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

(정답) 1) coredns

2) kube-controller-manager

3) kube-apiserver

4) etcd

 

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

1) kube-controller-manager

2) kube-proxy (정답)

4) kube-scheduler

5) kube-apiserver

아래 Tip 의 statics pod의 위치를 찾기 위한 방법정리 참고.

 

더보기

Statics Pod

statics pod의 위치를 찾기 위한 방법정리

1) kubelet관련된 프로세스 정보를 가져온다

- aux명령어는 ps명령어에서 a, u, x 를 합쳐서 쓰는 명령어이다

a: 터미널에 종속되지 않은 모든 프로세스 출력

u: 프로세스의 소유자를 기준으로 출력

x: BSD계열로 프로세스의 소유자를 기준으로 출력

ps -aux | grep kubelet

해당 명령어를 치게되면 다음과같은 부분이 보일텐데

--config=/var/lib/kubelet/config.yaml

이 파일안에 내용을 cat으로 읽어보면, 다음과같은 텍스트가 발견됨.

staticPodPath: /etc/kubernetes/manifests

즉, 현재 Static Pod의 위치는 위와같이 설정되어있는것을 알수있음.

 

 

etcd.yaml
kube-apiserver.yaml
kube-controller-manager.yaml
kube-scheduler.yaml

 

04. On which nodes are the static pods created currently?

1) controlplane (정답)

2) controlplane & node01

3) node01

4) All Nodes

root@controlplane:~# kubectl get pods --all-namespaces -o wide
NAMESPACE     NAME                                   READY   STATUS    RESTARTS   AGE   IP           NODE           NOMINATED NODE   READINESS GATES
kube-system   coredns-74ff55c5b-26bjz                1/1     Running   0          41m   10.244.0.2   controlplane   <none>           <none>
kube-system   coredns-74ff55c5b-fkdrx                1/1     Running   0          41m   10.244.0.3   controlplane   <none>           <none>
kube-system   etcd-controlplane                      1/1     Running   0          41m   10.6.64.6    controlplane   <none>           <none>
kube-system   kube-apiserver-controlplane            1/1     Running   0          41m   10.6.64.6    controlplane   <none>           <none>
kube-system   kube-controller-manager-controlplane   1/1     Running   0          41m   10.6.64.6    controlplane   <none>           <none>
kube-system   kube-flannel-ds-5zj78                  1/1     Running   0          41m   10.6.64.6    controlplane   <none>           <none>
kube-system   kube-flannel-ds-zp2gr                  1/1     Running   0          40m   10.6.64.8    node01         <none>           <none>
kube-system   kube-proxy-8lptx                       1/1     Running   0          40m   10.6.64.8    node01         <none>           <none>
kube-system   kube-proxy-l4ld5                       1/1     Running   0          41m   10.6.64.6    controlplane   <none>           <none>
kube-system   kube-scheduler-controlplane            1/1     Running   0          41m   10.6.64.6    controlplane   <none>           <none>

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

 

정답 : staticPodPath: /etc/kubernetes/manifests

 

풀이법은 3번 Tip 과 동일

 

06. How many pod definition files are present in the manifests folder?

 

정답 : 4

root@controlplane:~# cd /etc/kubernetes/manifests
root@controlplane:/etc/kubernetes/manifests# ls
etcd.yaml  kube-apiserver.yaml  kube-controller-manager.yaml  kube-scheduler.yaml

# 위와 같이 4개의 yaml 파일이 있는것을 확인.

 

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

 

정답 : k8s.gcr.io/kube-apiserver:v1.20.0

cat kube-apiserver.yaml 

image: k8s.gcr.io/kube-apiserver:v1.20.0

확인.

 

08. Create a static pod named static-busybox that uses the busybox image and the command sleep 1000


  • Name: static-busybox
  • Image: busybox
#
apiVersion: v1
kind: Pod
metadata:
  labels:
    run: static-busybox
  name: static-busybox
spec:
  containers:
  - image: busybox
    name: static-busybox
    args:
    - sleep
    - "1000"
  dnsPolicy: ClusterFirst
  restartPolicy: Always
# 정답

kubectl run --restart=Never --image=busybox static-busybox --dry-run=client -o yaml --command -- sleep 1000 > /etc/kubernetes/manifests/static-busybox.yaml

 

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

 

 

  • Name: static-busybox
  • Image: busybox:1.28.4
# 오답
kubectl replace -f /etc/kubernetes/manifests/static-busybox.yaml
kubectl run --restart=Never --image=busybox:1.28.4 static-busybox --dry-run=client -o yaml --command -- sleep 1000 > /etc/kubernetes/manifests/static-busybox.yaml

 

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

First, let's identify the node in which the pod called static-greenbox is created.
To do this, run:

root@controlplane:~# kubectl get pods --all-namespaces -o wide  | grep static-greenbox
default       static-greenbox-node01                 1/1     Running   0          19s     10.244.1.2   node01       <none>           <none>
root@controlplane:~#
From the result of this command, we can see that the pod is running on node01.


Next, SSH to node01 and identify the path configured for static pods in this node.
Important: The path need not be /etc/kubernetes/manifests.
Make sure to check the path configured in the kubelet configuration file.

root@controlplane:~# ssh node01 
root@node01:~# ps -ef |  grep /usr/bin/kubelet 
root       752   654  0 00:30 pts/0    00:00:00 grep --color=auto /usr/bin/kubelet
root     28567     1  0 00:22 ?        00:00:11 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --config=/var/lib/kubelet/config.yaml --network-plugin=cni --pod-infra-container-image=k8s.gcr.io/pause:3.2
root@node01:~# grep -i staticpod /var/lib/kubelet/config.yaml
staticPodPath: /etc/just-to-mess-with-you
root@node01:~# 
Here the staticPodPath is /etc/just-to-mess-with-you


Navigate to this directory and delete the YAML file:
root@node01:/etc/just-to-mess-with-you# ls
greenbox.yaml
root@node01:/etc/just-to-mess-with-you# rm -rf greenbox.yaml 
root@node01:/etc/just-to-mess-with-you#
Exit out of node01 using CTRL + D or type exit. You should return to the controlplane node. Check if the static-greenbox pod has been deleted:
root@controlplane:~# kubectl get pods --all-namespaces -o wide  | grep static-greenbox
root@controlplane:~#
 

 


Bookmark

 

https://kubernetes.io/ko/docs/tasks/configure-pod-container/static-pod/

 

스태틱(static) 파드 생성하기

스태틱 파드 는 API 서버 없이 특정 노드에 있는 kubelet 데몬에 의해 직접 관리된다. 컨트롤 플레인에 의해 관리되는 파드(예를 들어 디플로이먼트(Deployment))와는 달리, kubelet 이 각각의 스태틱 파

kubernetes.io