[k8s] CKAD 자격증 연습문제 – 1


위 게시글에 있는 Git에 있는 연습문제들을 간단하게 풀어보면서 어려운 문제들이나 헷갈리는 문제들은 나만의 이해법으로 작성하면서 공부해보겠다.




[su_accordion]
[su_spoiler title=”Create a namespace called ‘mynamespace’ and a pod with image nginx called nginx on this namespace” open=”no” style=”default” icon=”plus” anchor=”” anchor_in_url=”no” class=””]
kubectl create ns mynamespace
kuberctl run nginx –image=nginx –restart=Never -n mynamespace
(정답에 –restart가 있는데 단 한번만 실행하게끔 해야해서 옵션을 넣은건지 궁금했다.)
[/su_spoiler]
[su_spoiler title=”Create the pod that was just described using YAML” open=”no” style=”default” icon=”plus” anchor=”” anchor_in_url=”no” class=””]
kubectl run nginx –image-nginx –restsart=Never –dry-run=client -n mynamespace -o yaml > pod.yaml
(위의 문제랑 연결되는 것 같은데, 그런 셜명이 아쉽고 생각보다 –dry-run=client는 많이 사용하게 될 것 같다.)
[/su_spoiler]
[su_spoiler title=”Create a busybox pod (using kubectl command) that runs the command ‘env’. Run it and see the output” open=”no” style=”default” icon=”plus” anchor=”” anchor_in_url=”no” class=””]
kubectl run busybox –image=busybox –command –restart=Never -it –rm — env
(먼저 –command를 써서 — 뒤에 나오는 명령어를 실행하고 -it 옵션으로 로그를 볼 수 있게 해당 컨테이너에 접속하고 –rm으로 커맨드를 실행하고 자동으로 삭제되게 옵션을 주는 것 같다.)
[/su_spoiler]
[su_spoiler title=”Create a busybox pod (using YAML) that runs the command ‘env’. Run it and see the output” open=”no” style=”default” icon=”plus” anchor=”” anchor_in_url=”no” class=””]
kubectl run busybox –image=busybox –restart=Never –dry-run=client -o yaml –command — env > pod.yaml
kubectl apply -f pod.yaml
kubectl logs busybox
(위 문제랑 크게 다를 건 없고, yaml으로 띄워야하기에 –dry-run 후 apply를 하고 logs로 출력했다.)
[/su_spoiler]
[su_spoiler title=”Get the YAML for a new namespace called ‘myns’ without creating it” open=”no” style=”default” icon=”plus” anchor=”” anchor_in_url=”no” class=””]
kubect create ns myns –dry-run=client -o yaml
(> yaml을 사용하여 저장까지 하는 줄 알았지만 그럴 필요는 없는 것 같다. 해도 되고 안 해도 될 듯 하다.)
[/su_spoiler]
[su_spoiler title=”Create the YAML for a new ResourceQuota called ‘myrq’ with hard limits of 1 CPU, 1G memory and 2 pods without creating it” open=”no” style=”default” icon=”plus” anchor=”” anchor_in_url=”no” class=””]
kubectl create quota myrq –hard=cpu=1,memory=1G,pods=2 –dry-run=client -o yaml
(이 부분은 조금 어색했는데 myrq라는 quota를 생성하고 hard limit 값을 설정해주는 명령어들은 외워둬야겠다.)
[/su_spoiler]
[su_spoiler title=”Get pods on all namespaces” open=”no” style=”default” icon=”plus” anchor=”” anchor_in_url=”no” class=””]
kubectl all pod -A
(너무 쉬운 문제… 이런 문제만 나왔으면…)
[/su_spoiler]
[su_spoiler title=”Create a pod with image nginx called nginx and expose traffic on port 80″ open=”no” style=”default” icon=”plus” anchor=”” anchor_in_url=”no” class=””]
kubectl run nginx –image=nginx –port=80
(업무에선 대부분 yaml으로 관리하다 보니 –port와 같은 옵션들이 어색하게만 느껴진다.)
[/su_spoiler]
[su_spoiler title=”Change pod’s image to nginx:1.24.0. Observe that the container will be restarted as soon as the image gets pulled” open=”no” style=”default” icon=”plus” anchor=”” anchor_in_url=”no” class=””]
kubectl set image pod/nginx nginx=nginx:1.24.0
kubectl get pod/nginx -w
(set을 써서 pod에 image를 업데이트하고 -w 옵션으로 실시간 확인을 하는데, 나는 주로 watch kubect~~를 쓰는데 기능자체는 비슷할 듯 하다.)
[/su_spoiler]
[su_spoiler title=”Get nginx pod’s ip created in previous step, use a temp busybox image to wget its ‘/'” open=”no” style=”default” icon=”plus” anchor=”” anchor_in_url=”no” class=””]
kubectl get pod nginx -o wide
(–rm과 -it와 같이 작대기 개수에 주의하고, –command 옵션이 없는 것과 있는 것의 차이는 image에 있는 entrypoint를 따르냐 안 따르냐의 차이인 것 같은데 이 부분은 좀 더 찾아봐야겠다.
[/su_spoiler]
[su_spoiler title=”Get pod’s YAML” open=”no” style=”default” icon=”plus” anchor=”” anchor_in_url=”no” class=””]
kubectl get pod nginx -o yaml
[/su_spoiler]
[su_spoiler title=”Get information about the pod, including details about potential issues (e.g. pod hasn’t started)” open=”no” style=”default” icon=”plus” anchor=”” anchor_in_url=”no” class=””]
kubectl describe pod nginx
(pod에 문제가 있을 경우에는 주로 describe, logs 2가지 명령어를 많이 쓴다.)
[/su_spoiler]
[su_spoiler title=”Get pod logs” open=”no” style=”default” icon=”plus” anchor=”” anchor_in_url=”no” class=””]
kubectl logs nginx
[/su_spoiler]
[su_spoiler title=”If pod crashed and restarted, get logs about the previous instance” open=”no” style=”default” icon=”plus” anchor=”” anchor_in_url=”no” class=””]
kubectl logs nginx -p
(logs는 주로 -f, –tail 옵션을 많이 줬었는데 -p 옵션도 알고 있어야겠다.)
[/su_spoiler]
[su_spoiler title=”Execute a simple shell on the nginx pod” open=”no” style=”default” icon=”plus” anchor=”” anchor_in_url=”no” class=””]
kubectl exec -it nginx — /bin/sh
(문제가 좀 애매한 것 같은데 결국 shell 명령어를 pod에서 실행해봐라~ 라는 느낌이다.)
[/su_spoiler]
[su_spoiler title=”Create a busybox pod that echoes ‘hello world’ and then exits” open=”no” style=”default” icon=”plus” anchor=”” anchor_in_url=”no” class=””]
kubectl run busybox –image=busybox -it –restart=Never — echo ‘hello world’
(명령어를 날리고 pod를 삭제하는 것이 아닌 exit이기에 –rm 옵션이 없는 건가 싶다.)
[/su_spoiler]
[su_spoiler title=”Do the same, but have the pod deleted automatically when it’s completed” open=”no” style=”default” icon=”plus” anchor=”” anchor_in_url=”no” class=””]
kubectl run busybox –image=busybox -it –rm –restart=Never — echo ‘hello world’
(의문점이 생기자마자 바로 이런 문제가..)
[/su_spoiler]
[su_spoiler title=”Create an nginx pod and set an env value as ‘var1=val1’. Check the env value existence within the pod” open=”no” style=”default” icon=”plus” anchor=”” anchor_in_url=”no” class=””]
kubectl run nginx –restart=Never –image=nginx –env=var1=val1 -it –rm — env
(다양하게 확인할 수 있을 것 같은데 –env=var1=var1 문법에 익숙해져야할 것 같다.)
[/su_spoiler]
[/su_accordion]

위의 문제들이 실제 CKAD 문제들이랑 유사할지는 모르겠으나, 대부분 kubectl 명령어로 진행되는 시험인 만큼 충분한 도움이 될 것이라고 판단했다.

각 챕터별로 나오는 연습문제들을 풀어보고 이에 대한 나만의 이해법을 작성하면서 계속 공부해야겠다.

위로 스크롤