kubernets

 

KodeKloud

 

Udemy 강좌에서 KodeKloud 라는 문제풀이 환경을 제공하기에 한번 해봤다.

1시간 안에 풀어야하는데, 생각보다 널널했다.

 

Pods 파트 이고 01 ~ 13 번째 문제 모두에 대한 문제를 정리해볼까 한다.

 

한번 풀고나면 이전 단계로 못돌아가기 때문에 2번 부터 제대로 시작

 

1. 현재 Pods 숫자는?

1번 문제의 영어 지문을 못봤는데 대충 이런 의미였다.

 

kubectl get pods

 

 

이렇게 실행했는데 No resources found in default namespace. 라고 나왔던 것 같다.

 

뭐지? 설정이 잘못되었나? 했는데 정답은 0 이 었다. (당황;)

 

2. Create a new pod with the nginx image.

아.. 이건 별 대수롭지 않게 생각하고 따로 정리를 안해두었는데

공식 문서에서 검색해보니 쉽게 찾을 수 있었다.

실제 시험을 볼 때도 쿠버네티스 공식 문서의 매뉴얼을 검색할 수 있다고 하니 실전에서도 큰 어려움은 없을 것 같다.

 

kubectl run nginx --image=nginx

 

쉽게 해결.

 

2번까지 미리 풀어놓고 블로그에 부랴부랴 정리하니 시간이

 

 

아직까지 확실히 여유가 있었다.

실제 시험도 이정도라면 좋겠다.

 

3. How many pods are created now?

Note: We have created a few more pods. So please check again.

 

$ kubectl get pods

NAME            READY   STATUS    RESTARTS   AGE
nginx           1/1     Running   0          11m
newpods-wj9pc   1/1     Running   0          21s
newpods-cl7k9   1/1     Running   0          21s
newpods-7zkz9   1/1     Running   0          21s

 

4개.

 

4. What is the image used to create the new pods?

You must look at one of the new pods in detail to figure this out.

 

$ kubectl get pods

NAME            READY   STATUS    RESTARTS   AGE
nginx           1/1     Running   0          15m
newpods-wj9pc   1/1     Running   0          3m43s
newpods-cl7k9   1/1     Running   0          3m43s
newpods-7zkz9   1/1     Running   0          3m43s

 

이렇게 확인 후 힌트를 보고 describe 라는 명령어를 알았다.

 

kubectl describe pods newpods-7zkz9

 

이걸 사용해서

 

Name:         newpods-7zkz9
Namespace:    default
Priority:     0
Node:         controlplane/172.25.0.47
Start Time:   Mon, 07 Mar 2022 17:31:25 +0000
Labels:       tier=busybox
Annotations:  <none>
Status:       Running
IP:           10.42.0.11
IPs:
  IP:           10.42.0.11
Controlled By:  ReplicaSet/newpods
Containers:
  busybox:
    Container ID:  containerd://88484455dbc443ee11141b403ab810974e2f8f83d2d7e77456656f40eb0a31c8
    Image:         busybox
    Image ID:      docker.io/library/busybox@sha256:34c3559bbdedefd67195e766e38cfbb0fcabff4241dbee3f390fd6e3310f5ebc
    Port:          <none>
    Host Port:     <none>
    Command:
      sleep
      1000
    State:          Running
      Started:      Mon, 07 Mar 2022 17:31:33 +0000
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-zxtc7 (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  kube-api-access-zxtc7:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  7m7s  default-scheduler  Successfully assigned default/newpods-7zkz9 to controlplane
  Normal  Pulling    7m6s  kubelet            Pulling image "busybox"
  Normal  Pulled     7m1s  kubelet            Successfully pulled image "busybox" in 4.422367428s
  Normal  Created    7m1s  kubelet            Created container busybox
  Normal  Started    7m    kubelet            Started container busybox

 

를 사용해 이미지를 확인할 수 있었다. busybox.

다음엔 kubectl describe pods [파드명] | grep -i image 로 검색해서 보자

 

5. Which nodes are these pods placed on?

You must look at all the pods in detail to figure this out.

 

$ kubectl get node

NAME           STATUS   ROLES                  AGE   VERSION
controlplane   Ready    control-plane,master   27m   v1.22.2+k3s2

 

정답은 controlplane.

다음엔 kubectl get pods -o wide 로 확인해보자

 

6. How many containers are part of the pod webapp?

Note: We just created a new POD. Ignore the state of the POD for now.

 

이쯤되면 kubectl get pods 는 거의 ls -al 급의 커맨드다.

$ kubectl get pods

NAME            READY   STATUS         RESTARTS   AGE
nginx           1/1     Running        0          22m
newpods-wj9pc   1/1     Running        0          11m
newpods-cl7k9   1/1     Running        0          11m
newpods-7zkz9   1/1     Running        0          11m
webapp          1/2     ErrImagePull   0          66s

 

kubectl describe pods webapp
Name:         webapp
Namespace:    default
Priority:     0
Node:         controlplane/172.25.0.47
Start Time:   Mon, 07 Mar 2022 17:41:28 +0000
Labels:       <none>
Annotations:  <none>
Status:       Pending
IP:           10.42.0.13
IPs:
  IP:  10.42.0.13
Containers:
  nginx:
    Container ID:   containerd://77220aa0298d2707b6a12bd40d95cfd1183912add48b1b69a42a2d3767c73ddb
    Image:          nginx
    Image ID:       docker.io/library/nginx@sha256:1c13bc6de5dfca749c377974146ac05256791ca2fe1979fc8e8278bf0121d285
    Port:           <none>
    Host Port:      <none>
    State:          Running
      Started:      Mon, 07 Mar 2022 17:41:32 +0000
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-dnvjp (ro)
  agentx:
    Container ID:   
    Image:          agentx
    Image ID:       
    Port:           <none>
    Host Port:      <none>
    State:          Waiting
      Reason:       ImagePullBackOff
    Ready:          False
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-dnvjp (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes:
  kube-api-access-dnvjp:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason     Age                    From               Message
  ----     ------     ----                   ----               -------
  Normal   Scheduled  4m16s                  default-scheduler  Successfully assigned default/webapp to controlplane
  Normal   Pulling    4m13s                  kubelet            Pulling image "nginx"
  Normal   Pulled     4m13s                  kubelet            Successfully pulled image "nginx" in 577.526184ms
  Normal   Created    4m13s                  kubelet            Created container nginx
  Normal   Started    4m12s                  kubelet            Started container nginx
  Warning  Failed     3m4s (x4 over 4m11s)   kubelet            Error: ImagePullBackOff
  Normal   Pulling    2m50s (x4 over 4m12s)  kubelet            Pulling image "agentx"
  Warning  Failed     2m50s (x4 over 4m12s)  kubelet            Failed to pull image "agentx": rpc error: code = Unknown desc = failed to pull and unpack image "docker.io/library/agentx:latest": failed to resolve reference "docker.io/library/agentx:latest": pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed
  Warning  Failed     2m50s (x4 over 4m12s)  kubelet            Error: ErrImagePull
  Normal   BackOff    2m34s (x5 over 4m11s)  kubelet            Back-off pulling image "agentx"

 

 

어제 배운 Containers 를 보고 2개인 것을 알았다.

 

7. What images are used in the new webapp pod?

You must look at all the pods in detail to figure this out.

 

위의 내용을 보고도 풀이가 가능했다.

답은 nginx + agentx

 

8. What is the state of the container agentx in the pod webapp?

Wait for it to finish the ContainerCreating state

 

이것도 위의 내용을 보고도 풀이가 가능했다.

답은 Error or Waiting

 

9. Why do you think the container agentx in pod webapp is in error?

Try to figure it out from the events section of the pod.

 

이것도 위의 내용을 보고도 풀이가 가능했지만 이미지가 잘못되었다고 선택 했더니 틀렸다.

애초에 이미지 이름이 잘못되었던 모양이다.

 

답은 A Docker image with this name doesn't exist on Docker Hub

 

10. What does the READY column in the output of the kubectl get pods command indicate?

 

처음에는 찍어보았으나

 

$ kubectl get pods

NAME            READY   STATUS         RESTARTS   AGE
nginx           1/1     Running        0          22m
newpods-wj9pc   1/1     Running        0          11m
newpods-cl7k9   1/1     Running        0          11m
newpods-7zkz9   1/1     Running        0          11m
webapp          1/2     ErrImagePull   0          66s

 

webapp 파드의 1/2 를 보고 알았다.

 

답은 Running Containers in POD/Total Containers in POD

 

11. Delete webapp pods

 

$ kubectl delete pods webapp
pod "webapp" deleted

 

 

12. Create a new pod with the name redis and with the image redis123.

 

apiVersion: v1
kind: Pod
metadata:
  name: redis
spec:
  containers:
    - name: redis
      image: redis123

 

$ kubectl apply -f sample.yaml 
pod/redis created

 

$ kubectl get pods

NAME            READY   STATUS         RESTARTS        AGE
nginx           1/1     Running        0               52m
newpods-wj9pc   1/1     Running        2 (6m59s ago)   40m
newpods-cl7k9   1/1     Running        2 (6m59s ago)   40m
newpods-7zkz9   1/1     Running        2 (7m ago)      40m
redis           0/1     ErrImagePull   0               4s

 

일부러 에러를 내게 만들고 완성.

kubectl run redis --image=redis123 --dry-run=client -o yaml > pod.yaml 로도 가능하다.

 

Tip !

  • kubectl get pod <pod-name> -o yaml > pod-definition.yaml 명령어를 사용하여 yaml 파일을 쉽게 만들 수 있다.

 

13. Now change the image on this pod to redis.

Once done, the pod should be in a running state.

 

전에 apply -f 로 만드는걸 배우길 잘했다는 생각이 들었다.

 

apiVersion: v1
kind: Pod
metadata:
  name: redis
spec:
  containers:
    - name: redis
      image: redis

 

$ kubectl apply -f sample.yaml 

pod/redis configured

$ kubectl get pods

NAME            READY   STATUS    RESTARTS        AGE
nginx           1/1     Running   0               54m
newpods-wj9pc   1/1     Running   2 (8m58s ago)   42m
newpods-cl7k9   1/1     Running   2 (8m58s ago)   42m
newpods-7zkz9   1/1     Running   2 (8m59s ago)   42m
redis           1/1     Running   0               2m3s

 

가볍게 완료.

 

kubectl edit pod redis 하여 image 를 변경하는 방법도 있다고 한다.

 

 

정리랑 동시에 같이 문제를 풀려다 보니 시간이 아슬아슬했다..

 

다음엔 캡쳐해두고 천천히 정리해보아야겠다.

 

완료

 

파드에 대한 간단한 문제로 구성이 되어있었고, 재밌었다.

다 풀고 나니 랩은 언제든지 다시 할 수 있는걸로 보인다.. 쓸데없이 고생했지만 한큐에 정리하면 나도 편하지 뭐.. 🤣