본문으로 건너뛰기

Mock Exam 1 오답 정리

1 (O)

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.

My Answer

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
args:
- /bin/sh
- -c
- >
while true;
do
echo "$(date)" >> /var/log/shared/date.log;
sleep 1;
done
volumeMounts:
- name: varlog
mountPath: /var/log/shared
- name: mc-pod-3
image: busybox:1
args: [/bin/sh, -c, 'tail -n+1 -F /var/log/shared/date.log']
volumeMounts:
- name: varlog
mountPath: /var/log/shared
volumes:
- name: varlog
emptyDir: {}

2 (O)

This question needs to be solved on node node01. To access the node using SSH, use the credentials below:

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.

My Answer

ssh bob@node01

sudo -i

cd ~

sudo apt install ./cri-docker_0.3.16.3-0.debian.deb

sudo systemctl start cri-docker
sudo systemctl enable cri-docker
  • systemctl start - 서비스 실행
  • systemctl enable - 재부팅 시에도 자동으로 시작되도록 설정
  • cf) aptapt-get, apt-cache 등의 기능을 하나르 모은 것
    • cli 창에서 설치를 입력할 때는 주로 apt를 사용한다. -> 그냥 apt만 기억해도 무방

3 (O)

On controlplane node, identify all CRDs related to VerticalPodAutoscaler and save their names into the file /root/vpa-crds.txt.

My Answer

kubectl get crd

kubectl get crd | grep vertical > /root/vpa-crds.txt
  • grep something : something이 포함된 줄만 찾아서 해당 '줄'만 출력함
  • | : 파이프 -> 파이프 앞의 결과를 파이프 뒤의 명령어로 넘겨줌
  • 즉, kubectl get crd의 결과를 grep vertical에 넘겨줌

4 (O)

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.

My Answer

apiVersion: v1
kind: Service
metadata:
name: messaging-service
spec:
selector:
tier: msg
ports:
- name: port
protocol: TCP
port: 6379
targetPort: 6379
  • port: 외부에서 서비스에 접속할 포트
  • targetPort: 서비스에서 받은 트래픽을 전달할 Pod 내부 컨테이너의 포트

5 (O)

Create a deployment named hr-web-app using the image kodekloud/webapp-color with 2 replicas.

My Answer

apiVersion: apps/v1
kind: Deployment
metadata:
name: hr-web-app
labels:
app: kodekloud
spec:
replicas: 2
selector:
matchLabels:
app: kodekloud
template:
metadata:
labels:
app: kodekloud
spec:
containers:
- name: kodekloud
image: kodekloud/webapp-color

6 (X)

A new application orange is deployed. There is something wrong with it. Identify and fix the issue.

My Answer

  • describe해서 이벤트를 봤다.
  • 그런데 뭐가 문제인지 모르겠어서 일단 시간상 넘어갔다.

Right Answer

  • describe해서 보는 것 까지는 맞다. 거기에 오타가 있었다.
  • command 부분에 sleep이 아니라 sleeep이 있었다.
  • 이를 고쳐서 Pod를 다시 생성하면 된다.

7 (O)

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.

My Answer

apiVersion: v1
kind: Service
metadata:
name: hr-web-app-service
spec:
type: NodePort
selector:
app: kodekloud
ports:
- port: 8080
targetPort: 8080
nodePort: 30082
  • 헷갈릴만한 부분) ServiceselectorDeploymentlabel이 아니라 Podlabel을 보고 찾아간다.

8 (X)

Create a Persistent Volume with the given specification: -

Volume namepv-analytics
Storage100Mi
Access modeReadWriteMany
Host path/pv/data-analytics

My Answer

apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-analytics
spec:
capacity:
storage: 100Mi
volumeMode: Filesystem
accessModes:
- ReadWriteMany
local:
path: /pv/data-analytics
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- controlplane

Right Answer

apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-analytics
spec:
capacity:
storage: 100Mi
accessModes:
- ReadWriteMany
hostPath:
path: /pv/data-analytics
  • hostPathlocal은 다르다.
  • 내가 한 것은 local
  • hostPath - Pod가 뜨는 노드에 볼륨이 배치됨 즉, 어디로 갈지 모름 (즉, 테스트, 개발 용)
  • local - NodeAffinity로 지정함, 어디로 갈지 정함 (특정 노드의 호스트 볼륨을 사용하기 위한 목적이 뚜렷함. prod 용)

9 (X)

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.

My Answer

  • Kubernetes docs에 HPA full example이 없어서 당황했다.
  • 더 찾아보면서 찾을 시간이 없는 것 같아서 일단 넘어갔다.

Right Answer

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: webapp-hpa
namespace: default
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
  • HPA full example은 HPA를 검색했을 때 HPA 페이지 다음으로 나오는 HPA WalkThrough 페이지에 있다.
  • 추가적으로 stabilization window의 경우 HPA WalkThrough 페이지의 full example에 없고, HPA 페이지에 있다.
  • 하지만, full이 아니라 헷갈릴 수 잇는데, behavior의 위치는 spec 바로 하위인 spec.behavior이다. (이건 외워야할 듯)

10 (X)

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.

My Answer

  • 시간없어서 못풀었다.

Right Answer

apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
name: analytics-vpa
namespace: default
spec:
targetRef:
apiVersion: apps/v1
kind: Deployment
name: analytics-deployment
updatePolicy:
updateMode: Recreate
  • VPA는 HPA와 다르게 메인 docs 페이지에서 full example이 있다.

11 (X)

Create a Kubernetes Gateway resource with the following specifications:

  1. Nameweb-gateway
  2. Namespacenginx-gateway
  3. Gateway Class Namenginx
  4. Listeners:
    • ProtocolHTTP
    • Port80
    • Namehttp

My Answer

  • 시간없어서 못풀었다.

Right Answer

apiVersion: gateway.networking.k8s.io/v1beta1
kind: Gateway
metadata:
name: web-gateway
namespace: nginx-gateway
spec:
gatewayClassName: nginx
listeners:
- name: http
protocol: HTTP
port: 80
  • Gateway docs 에 full example이 있어서 쉽게 풀수 있었던 문제다.

12 (X)

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.

My Answer

  • 시간없어서 못풀었다.

Right Answer

helm repo update

helm upgrade kk-mock1 nginx \
--namespace kk-ns \
--version 18.1.15
  • Helm 기본 명령어만 알아두면 쉽게 풀 수 있는 문제