https://beta.kodekloud.com/user/courses/udemy-labs-certified-kubernetes-administrator-with-practice-tests
1. How many pods exist on the system? In the current(default) namespace.
$ controlplane ~ ➜ kubectl get pods
No resources found in default namespace.
2. Create a new pod with the nginx image.
2-1 ) kubectl run 활용
# kubectl run <pods명> --image <사용이미지>
$ kubectl run nginx-pods --image nginx
2-2 ) yaml 로 실행
-- nginx-pods.yaml
apiVersion: v1
kind: Pod
metadata:
labels:
run: nginx
name: nginx-pods
spec:
containers:
- image: nginx
name: nginx
2-3) yaml 파일적용
$ kubectl apply -f nginx-pods.yaml
ps) yaml 쉽게 만드는 방법 - --dry-run=client -o yaml 옵션사용
$ kubectl run nginx-pods --image nginx --dry-run=client -o yaml
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: nginx-pods
name: nginx-pods
spec:
containers:
- image: nginx
name: nginx-pods
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}
https://kubernetes.io/docs/reference/kubectl/generated/kubectl_run/#synopsis
3. How many pods are created now? Note: We have created a few more pods. So please check again.
$ controlplane ~ ➜ k get pods
NAME READY STATUS RESTARTS AGE
nginx 1/1 Running 0 13s
newpods-krwlt 1/1 Running 0 4s
newpods-zj5jt 1/1 Running 0 4s
newpods-hjqcn 1/1 Running 0 4s
answer : 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.
## pods 정보확인하기
$ kubectl describe pods <파드명> -n <namespace>
$ kubectl describe pods newpods-krwlt
...중략
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 2m42s default-scheduler Successfully assigned default/newpods-krwlt to controlplane
Normal Pulling 2m43s kubelet Pulling image "busybox"
Normal Pulled 2m42s kubelet Successfully pulled image "busybox" in 325ms (325ms including waiting)
answer: busybox
5. Which nodes are these pods placed on? You must look at all the pods in detail to figure this out.
# 파드 정보를 더 자세히 보기 '-o wide' 옵션 사용.
$ kubectl get pods -o wide
$ controlplane ~ ✖ k get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx 1/1 Running 0 3m57s 10.42.0.9 controlplane <none> <none>
newpods-krwlt 1/1 Running 0 3m48s 10.42.0.10 controlplane <none> <none>
newpods-zj5jt 1/1 Running 0 3m48s 10.42.0.11 controlplane <none> <none>
newpods-hjqcn 1/1 Running 0 3m48s 10.42.0.12 controlplane <none> <none>
answer: controlplane
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.
controlplane ~ ➜ k get pods
NAME READY STATUS RESTARTS AGE
nginx 1/1 Running 0 5m29s
newpods-krwlt 1/1 Running 0 5m20s
newpods-zj5jt 1/1 Running 0 5m20s
newpods-hjqcn 1/1 Running 0 5m20s
webapp 1/2 ImagePullBackOff 0 26s
answer : 2
7. What images are used in the new webapp pod?
You must look at all the pods in detail to figure this out.
$ kubectl describe pods webapp
...중략
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 86s default-scheduler Successfully assigned default/webapp to controlplane
Normal Pulling 86s kubelet Pulling image "nginx"
Normal Pulled 86s kubelet Successfully pulled image "nginx" in 224ms (224ms including waiting)
Normal Created 86s kubelet Created container nginx
Normal Started 86s kubelet Started container nginx
Normal Pulling 46s (x3 over 86s) kubelet Pulling image "agentx"
Warning Failed 40s (x3 over 85s) kubelet Failed to pull image "agentx": 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 40s (x3 over 85s) kubelet Error: ErrImagePull
Normal BackOff 2s (x5 over 85s) kubelet Back-off pulling image "agentx"
Warning Failed 2s (x5 over 85s) kubelet Error: ImagePullBackOff
answer : nginx and agentx
8. What is the state of the container agentx in the pod webapp?
Wait for it to finish the ContainerCreating state
answer : error or waiting -> 위 describe 정보에서 참조.
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.
-> 위 Message 에서 agentx 이미지에 대해 'failed to pull and unpack image' 메시지 남음.
answer : A Docker image with this name dosen't exist on Docker Hub
10. What does the READY column in the output of the kubectl get pods command indicate?
$ controlplane ~ ➜ k get pods
NAME READY STATUS RESTARTS AGE
...
webapp 1/2 ImagePullBackOff 0 4m57s
#. 실행중/전체
answer: Running Container in POD/Total Containers in POD
11. Delete the webapp Pod.
Once deleted, wait for the pod to fully terminate.
# pod 삭제하기
# kubectl delete pods <파드명>
$ kubectl delete pods webapp
12. Create a new pod with the name redis and the image redis123.
Use a pod-definition YAML file. And yes the image name is wrong!
# redis123-pods.yaml
apiVersion: v1
kind: Pod
metadata:
name: redis
spec:
containers:
- image: redis123
name: redis
$ kubectl apply -f redis123-pods.yaml
13. Now change the image on this pod to redis.
Once done, the pod should be in a running state.
13-1. yaml 수정후 apply 로 적용.
# redis123-pods.yaml 파일 수정
apiVersion: v1
kind: Pod
metadata:
name: redis
spec:
containers:
- image: redis
name: redis
$ kubectl delete pods redis
$ kubectl apply -f redis123-pods.yaml
# 또는 --force 옵션 추가
$ kubectl apply -f redis123-pods.yaml --force
13-2. kubectl edit 이용
$ kubectl edit pods redis
### edit 파일
Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
kind: Pod
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"name":"redis","namespace":"default"},"spec":{"containers":[{"image":"redis","name":"redis"}]}}
creationTimestamp: "2024-05-27T14:09:36Z"
name: redis
namespace: default
resourceVersion: "1525"
uid: 7b318f8b-64b7-4077-b655-6f98e42f5b2e
spec:
containers:
- image: redis123 #### 해당 이미지 변경후 저장.
imagePullPolicy: Always
name: redis
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: kube-api-access-jzthm
readOnly: true
dnsPolicy: ClusterFirst
enableServiceLinks: true
nodeName: controlplane
'IT 기술 > k8s' 카테고리의 다른 글
[cka] Deployments (0) | 2024.05.28 |
---|---|
[cka] ReplicaSets (0) | 2024.05.27 |
[k8s] kubeadm token 생성하기. (0) | 2024.05.15 |
[k8s] etcd 백업 / 복원 하기 (0) | 2024.05.09 |
[k8s] 노드 상태 다루기 [drain/cordon/uncordon] (0) | 2024.04.25 |
댓글