CKA Mock Exam - 1
Q. 1 Multi-container Pod
Task: Create a Pod mc-pod in the mc-namespace namespace with three containers. The first container should be named mc-pod-1, run the nginx:1-alpine image, and set an environment variable NODE_NAME to the node name. The second container should be named mc-pod-2, run the busybox:1 image, and continuously log the output of the date command to the file /var/log/shared/date.log every second. The third container should have the name mc-pod-3, run the image busybox:1, and print the contents of the date.log file generated by the second container to stdout. Use a shared, non-persistent volume.
- 공식문서 링크:
- 검색 키워드:
emptyDir,fieldRef,downward api,environment variable pod field
Solution:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
apiVersion: v1
kind: Pod
metadata:
name: mc-pod
namespace: mc-namespace
spec:
containers:
- name: mc-pod-1
image: nginx:1-alpine
env:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: mc-pod-2
image: busybox:1
command: ["sh", "-c", "while true; do date >> /var/log/shared/date.log; sleep 1; done"]
volumeMounts:
- name: shared-volume
mountPath: /var/log/shared
- name: mc-pod-3
image: busybox:1
command: ["sh", "-c", "tail -f /var/log/shared/date.log"]
volumeMounts:
- name: shared-volume
mountPath: /var/log/shared
volumes:
- name: shared-volume
emptyDir: {}
Q. 2 Install Container Runtime (cri-docker)
Task: This question needs to be solved on node node01. To access the node using SSH, use the credentials below:
1
2
username: bob
password: caleston123
As an administrator, you need to prepare node01 to install kubernetes. One of the steps is installing a container runtime. Install the cri-docker_0.3.16.3-0.debian.deb package located in /root and ensure that the cri-docker service is running and enabled to start on boot.
- 공식문서 링크:
- 검색 키워드:
container runtimes,cri dockerd,docker engine
Solution:
1
2
3
4
5
6
7
8
ssh bob@node01 # password: caleston123
sudo -i
dpkg -i /root/cri-docker_0.3.16.3-0.debian.deb
apt-get install -f -y
systemctl daemon-reload
systemctl enable cri-docker.service cri-docker.socket
systemctl start cri-docker.service cri-docker.socket
systemctl status cri-docker.service
Q. 3 Identify CRDs
Task: On controlplane node, identify all CRDs related to VerticalPodAutoscaler and save their names into the file /root/vpa-crds.txt.
- 공식문서 링크:
- 검색 키워드:
kubectl get crd,custom resources,crd list
Solution:
1
2
kubectl get crd -o custom-columns=NAME:.metadata.name --no-headers | grep verticalpodautoscaler > /root/vpa-crds.txt
cat /root/vpa-crds.txt
Q. 4 Messaging Service
Task: Create a service named messaging-service to expose the messaging pod within the cluster on port 6379. The messaging pod is running in the default namespace.
- 공식문서 링크:
- 검색 키워드:
kubectl expose,service,clusterip
Solution:
1
kubectl expose pod messaging --port=6379 --name messaging-service
Q. 5 Create Deployment
Task: Create a deployment named hr-web-app using the image kodekloud/webapp-color with 2 replicas.
- 공식문서 링크:
- 검색 키워드:
kubectl create deployment,deployment,replicas
Solution:
1
kubectl create deployment hr-web-app --image=kodekloud/webapp-color --replicas=2
Q. 6 Fix Broken Pod (InitContainer)
Task: A new application orange is deployed. There is something wrong with it. Identify and fix the issue.
- 공식문서 링크:
- 검색 키워드:
init containers,initContainers,pod lifecycle
Solution:
1
2
3
4
kubectl describe pod orange
kubectl get pod orange -o yaml > orange.yaml
sed -i 's/sleeeep/sleep/g' orange.yaml
kubectl replace -f orange.yaml --force
Q. 7 Expose Deployment as NodePort
Task: Expose the hr-web-app created in the previous task as a service named hr-web-app-service, accessible on port 30082 on the nodes of the cluster. The web application listens on port 8080.
- 공식문서 링크:
- 검색 키워드:
Service NodePort,nodePort,service types
Solution:
1
2
3
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 hr-web-app-service.yaml to add nodePort: 30082 under spec.ports[0]
kubectl apply -f hr-web-app-service.yaml
Q. 8 Persistent Volume
Task: Create a Persistent Volume with the given specification:
- Volume name: pv-analytics
- Storage: 100Mi
- Access mode: ReadWriteMany
Host path: /pv/data-analytics
- 공식문서 링크:
- 검색 키워드:
PersistentVolume hostPath,persistent volume,hostPath volume
Solution:
1
2
3
4
5
6
7
8
9
10
11
12
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-analytics
spec:
capacity:
storage: 100Mi
volumeMode: Filesystem
accessModes:
- ReadWriteMany
hostPath:
path: /pv/data-analytics
1
kubectl apply -f pv-analytics.yaml
Q. 9 Horizontal Pod Autoscaler (HPA)
Task: Create a Horizontal Pod Autoscaler (HPA) with name webapp-hpa for the deployment named kkapp-deploy in the default namespace with the webapp-hpa.yaml file located under the root folder. Ensure that the HPA scales the deployment based on CPU utilization, maintaining an average CPU usage of 50% across all pods. Configure the HPA to cautiously scale down pods by setting a stabilization window of 300 seconds to prevent rapid fluctuations in pod count.
Note: The kkapp-deploy deployment is created for backend; you can check in the terminal.
- 공식문서 링크:
- 검색 키워드:
stabilizationWindowSeconds,horizontal pod autoscaler,hpa behavior,scale down
Solution:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: webapp-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: kkapp-deploy
minReplicas: 1
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50
behavior:
scaleDown:
stabilizationWindowSeconds: 300
1
kubectl apply -f webapp-hpa.yaml
Q. 10 Vertical Pod Autoscaler (VPA)
Task: Deploy a Vertical Pod Autoscaler (VPA) with name analytics-vpa for the deployment named analytics-deployment in the default namespace. The VPA should automatically adjust the CPU and memory requests of the pods to optimize resource utilization. Ensure that the VPA operates in Recreate mode, allowing it to evict and recreate pods with updated resource requests as needed.
- 공식문서 링크:
- 검색 키워드:
VerticalPodAutoscaler,vpa,vertical pod autoscaler
Solution:
1
2
3
4
5
6
7
8
9
10
11
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
name: analytics-vpa
spec:
targetRef:
apiVersion: apps/v1
kind: Deployment
name: analytics-deployment
updatePolicy:
updateMode: "Recreate"
1
kubectl apply -f analytics-vpa.yaml
Q. 11 Kubernetes Gateway
Task: Create a Kubernetes Gateway resource with the following specifications:
- Name: web-gateway
- Namespace: nginx-gateway
- Gateway Class Name: nginx
- Listeners:
- Protocol: HTTP
- Port: 80
- Name: http
- 공식문서 링크:
- 검색 키워드:
Gateway API spec,gateway api,gateway listeners
Solution:
1
2
3
4
5
6
7
8
9
10
11
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: web-gateway
namespace: nginx-gateway
spec:
gatewayClassName: nginx
listeners:
- name: http
protocol: HTTP
port: 80
1
kubectl apply -f web-gateway.yaml
Q. 12 Helm Repo and Upgrade
Task: One co-worker deployed an nginx helm chart kk-mock1 in the kk-ns namespace on the cluster. A new update is pushed to the helm chart, and the team wants you to update the helm repository to fetch the new changes.
After updating the helm chart, upgrade the helm chart version to 18.1.15.
- 공식문서 링크:
- 검색 키워드:
helm upgrade,helm repo update,helm search,helm list
Solution:
1
2
3
4
5
helm list -n kk-ns
helm repo update
helm search repo kk-mock1/nginx --versions
helm upgrade kk-mock1 kk-mock1/nginx -n kk-ns --version 18.1.15
helm list -n kk-ns
문제 풀이 팁
kubectl explain 활용법
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 리소스의 전체 구조 확인
kubectl explain <resource>
# 특정 필드의 상세 정보 확인
kubectl explain <resource>.spec
kubectl explain <resource>.spec.field
# 재귀적으로 모든 필드 확인
kubectl explain <resource> --recursive
# 예시
kubectl explain pod.spec.containers.env
kubectl explain service.spec.type
kubectl explain deployment.spec.replicas
공식문서 검색 전략
- Kubernetes 공식 문서: https://kubernetes.io/docs/
- kubectl 치트시트: https://kubernetes.io/docs/reference/kubectl/cheatsheet/
- API Reference: https://kubernetes.io/docs/reference/kubernetes-api/
- 시험 중 검색 키워드:
kubectl <resource>(예:kubectl deployment)kubernetes <개념>(예:kubernetes service)<resource> example(예:pod example)
시험 시 주의사항
- 항상 namespace 확인:
-n옵션 사용 - dry-run 활용:
--dry-run=client -o yaml로 템플릿 생성 - kubectl explain 활용: 필드명이나 구조가 불확실할 때
- 리소스 확인:
kubectl get,kubectl describe로 검증 - 공식문서 즐겨찾기: 시험 시작 전 주요 페이지 북마크