Exam Tasks and Solutions
Q. 1
Task:
Deploy a pod named nginx-pod using the nginx:alpine image.
Solution:
kubectl run nginx-pod --image=nginx:alpine
Q. 2
Task:
Deploy a pod named messaging using the redis:alpine image with a label tier=msg.
Solution:
kubectl run messaging --image=redis:alpine -l tier=msg
Q. 3
Task:
Create a namespace named apx-x9984574.
Solution:
kubectl create namespace apx-x9984574
Q. 4
Task:
Get the list of nodes in JSON format and store it in /opt/outputs/nodes-z3444kd9.json.
Solution:
kubectl get nodes -o json > /opt/outputs/nodes-z3444kd9.json
Q. 5
Task:
Create a service messaging-service to expose the messaging application on port 6379 within the cluster.
Solution:
kubectl expose pod messaging --port=6379 --name=messaging-service
Q. 6
Task:
Create a deployment named hr-web-app using the image kodekloud/webapp-color with 2 replicas.
Solution:
kubectl create deployment hr-web-app --image=kodekloud/webapp-color --replicas=2
Q. 7
Task:
Create a static pod named static-busybox on the controlplane node using the busybox image and command sleep 1000.
Solution:
kubectl run --restart=Never --image=busybox static-busybox --dry-run=client -o yaml --command -- sleep 1000 > /etc/kubernetes/manifests/static-busybox.yaml
Q. 8
Task:
Create a pod named temp-bus in the finance namespace using the image redis:alpine.
Solution:
kubectl run temp-bus --image=redis:alpine -n finance
Q. 9
Task:
Fix the issue with the orange pod where the command sleeeep 2; is incorrect.
Solution:
- View pod details:
kubectl describe pod orange
- Correct the command:
kubectl edit pod orange
- Update:
yaml
Command: - sh - -c - sleep 2;
- Replace the pod:
kubectl replace -f /tmp/kubectl-edit-xxxx.yaml --force
Q. 10
Task:
Expose the hr-web-app deployment as a service hr-web-app-service accessible on port 30082 on the nodes.
Solution:
- Generate the service YAML:
kubectl expose deployment hr-web-app --type=NodePort --port=8080 --name=hr-web-app-service --dry-run=client -o yaml > hr-web-app-service.yaml
- Edit the YAML to add nodePort:
nodePort: 30082
- Apply the service:
kubectl apply -f hr-web-app-service.yaml
Q. 11
Task:
Retrieve the osImage of all nodes using JSON PATH and store it in /opt/outputs/nodes_os_x43kj56.txt.
Solution:
kubectl get nodes -o jsonpath='{.items[*].status.nodeInfo.osImage}' > /opt/outputs/nodes_os_x43kj56.txt
Q. 12
Task:
Create a Persistent Volume named pv-analytics with the following specifications:
- Storage: 100Mi
- Access mode: ReadWriteMany
- Host path: /pv/data-analytics
Solution:
Persistent Volume YAML:
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-analytics
spec:
capacity:
storage: 100Mi
volumeMode: Filesystem
accessModes:
- ReadWriteMany
hostPath:
path: /pv/data-analytics
Apply the YAML:
kubectl apply -f pv-analytics.yaml
한 번 더 풀었는데도 또 틀려버린 3문제 ㄱ-
또!!! 틀린 정보 및 설명
1. Messaging Service
문제:
- kubectl expose pod messaging --port=6379 --name messaging-service 명령어로 생성된 서비스에서 포트 설정이 잘못되었습니다.
- Port는 80/TCP, TargetPort는 6379/TCP로 설정되어 Pod에 적절히 매핑되지 않았습니다.
원인:
- --port 옵션은 Service의 외부 노출 포트를 지정하며, --target-port 옵션이 Pod의 컨테이너 포트를 매핑합니다.
- --target-port가 누락되어 기본값 80이 설정되었습니다.
해결 방법:
kubectl expose pod messaging --port=6379 --target-port=6379 --name=messaging-service
2. temp-bus Pod
문제:
- kubectl get pods -n temp-bus와 kubectl describe pod finance -n temp-bus 명령어에서 네임스페이스와 Pod 이름 간의 불일치가 발생했습니다.
- finance라는 이름이 아니라 temp-bus 네임스페이스 안의 finance Pod를 잘못 요청했습니다.
원인:
- kubectl get pods -n temp-bus는 올바른 네임스페이스에 Pod가 있음을 나타냅니다.
- 하지만 Pod 이름 finance로 조회하여 NotFound 오류가 발생했습니다.
해결 방법:
kubectl describe pod finance -n temp-bus
위 명령어는 이미 실행된 상태에서 정상적으로 Pod 세부 정보를 가져왔습니다.
3. hr-web-app-service Service
문제:
- TargetPort와 NodePort 설정이 잘못되었습니다.
- TargetPort: 30082/TCP로 설정되었지만, 실제 Pod는 8080 포트를 리스닝하고 있습니다.
- NodePort는 명시적으로 30082로 설정해야 하지만, 자동 할당된 32005가 사용되었습니다.
원인:
- NodePort는 명시적으로 설정되지 않으면 Kubernetes가 자동으로 할당합니다.
- TargetPort는 Pod 컨테이너 포트를 정확히 설정해야 합니다.
해결 방법:
YAML 파일 수정:
ports: - port: 8080 targetPort: 8080 nodePort: 30082
수정된 파일 적용:
kubectl apply -f hr-web-app-service.yaml
정리
Messaging Service | TargetPort가 누락되어 Pod와 매핑되지 않음 | --target-port=6379를 추가하여 명령어 수정 |
temp-bus Pod | 잘못된 Pod 이름으로 조회 요청 (finance 대신 temp-bus 네임스페이스에 있는 Pod 확인 필요) | kubectl describe pod finance -n temp-bus |
hr-web-app-service | TargetPort 및 NodePort가 잘못 설정 | TargetPort를 Pod의 컨테이너 포트 8080으로 수정, NodePort를 30082로 명시적으로 설정 |
'쿠버네티스' 카테고리의 다른 글
[쿠버네티스] 치트 메모장 (0) | 2025.01.21 |
---|---|
[쿠버네티스] CKA - Mock Exam2 정리 (0) | 2025.01.18 |
[쿠버네티스] pod 심화 과정 - 멀티 컨테이너 생성, 사이드카 파드 생성 (0) | 2024.12.28 |
Kubernetes RBAC(Role-Based Access Control) 정리 (0) | 2024.12.22 |
[쿠버네티스] 아키텍쳐 정리 및 간단한 실습 정리 (4) | 2024.12.15 |