728x90

▶ Mock Test link : https://beta.kodekloud.com/user/courses/udemy-labs-certified-kubernetes-administrator-with-practice-tests 

 

Sign In | KodeKloud

Welcome to KodeKloud By signing up you agree to our privacy policy

beta.kodekloud.com


▶ 시험 환경설정

 

(1) 공식문서 열어주기
      => https://kubernetes.io/docs/home/

(2) 자동완성 설정해주기 - tab 누를시 적용되도록
#자동완성
source <(kubectl completion bash) # set up autocomplete in bash into the current shell, bash-completion package should be installed first.
echo "source <(kubectl completion bash)" >> ~/.bashrc # add autocomplete permanently to your bash shell.

#별칭
alias k=kubectl
complete -o default -F __start_kubectl k

 

 


▶ 접속 가능한 참고 사이트 
https://kubernetes.io/docs/home/


01. Deploy a pod named nginx-pod using the nginx:alpine image.

문제 유형 : 파드 생성 

더보기

▶ nginx:alpine 이미지의 nignx-pod라는 파드 생성

k run nginx-pod --image=nginx:alpine

 

▶ 검증

k get pod #동작중인 파드확인

k describe pod nginx-pod #특정 파드의 상세 정보 확인
# Containers:
#     Image:		nginx:alpine

 

 


02. Deploy a messaging pod using the redis:alpine image with the lables set to tier=msg .

문제 유형 : 라벨을 붙인 파드 배포 

더보기

▶라벨 설정 옵션

k run --help
#Create and run a particular image in a pod
#Examples:
#	~
#	#Start a hazelcast pod and set labels "app=hazelcast" and "env=prod" in the container.
#	kubectl run hazelcast --image=hazelcast/hazelcast --labels="app=hazelcast,env=prod"

 

▶ pod 이름 messaging, 이미지 redis:alpine 파드 생성

k run messaging --image=redis:alpine --labels="tier=msg"

 

▶ 검증

k get pod #동작중인 파드확인

k describe pod messaging  #특정 파드의 상세 정보 확인
#Labels:	tier=msg
#~
# Containers:
#     Image:		redis:alpine

 


03. Create a namespace named apx-x9984574

문제 유형 : namespace 생성

더보기

▶ apx-x9984574 이름을 가진 namespace 생성

k create namespace apx-x9984754

 

▶ 검증

k get ns #생성된 namespace 확인

 


04. Get the list of nodes in JSON format and store it in a file at /opt/outputs/nodes-z3444kd9.json

문제 유형 : json포맷으로 파일 생성 및 해당 경로에 저장

더보기

▶ 과정

#노드 목록 확인
k get nodes

#노드 목록 확인 + json포맷
k get nodes -o json

#해당 경로에 저장(해당 경로로 리다이렉트)
k get nodes -o json > /opt/outputs/nodes-z3444kd9.json

 

▶ 검증

cat /opt/outputs/nodes-z3444kd9.json

 


⭐05. Create a service messaging-service to expose the messaging application within the cluster on port 6379 .

문제 유형 : 서비스 생성 + 정해진 포트

더보기

▶ 과정

#현재 동작중인 파드 확인
k get pods

#현재 동작중인 서비스 확인
k get svc

#expose 예시 보기
k expose --help
#Create  a service for a replicated~
kubectl expose rc nginx --port=80 --target-port=8000

#ClusterIP 서비스 타입으로 messaging 서비스 생성
k expose pod messaging --port 6379 --name messaging-service

 

▶ 검증

# 생성된 서비스 확인
k get svc

# 라벨 확인
k describe svc messaging-service
#Labels:	tier=msg
#~
#Endpoints:	x.x.x.x:6379

#서비스 IP와 pod가 동작하는 IP가 일치하는지 확인
k get pods -o wide
#NAME		READY		 ~ 		IP
#messaging	1/1				x.x.x.x

 


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

문제 유형 : replica가 2인 파드 생성

더보기

▶ 과정

#deploy 생성
k create deployment hr-web-app --image=kodekloud/webapp-color --replicas=2

 

▶ 검증

k get deploy # 웹 앱 배포 확인

#정해진 이미지 사용 확인
k describe deploy hr-web-app
#Containers:
#	Image: kodekloud/webapp-color

 


⭐07. Create a static pod named static-busybox on the controlplane node that uses the busybox image and the command sleep 1000 .

문제 유형 : Static 파드 생성

더보기

▶ 과정

# static pod
#--dry-run=client옵션의 위치
k run static-busybox --image=busybox --dry-run=client -o yaml --command sleep 1000

#예상결과를 yaml에 넣기
k run static-busybox --image=busybox --dry-run=client -o yaml --command sleep 1000 > static-busybox.yaml

#결과 확인 
cat static-busybox.yaml
#Containers:
#- command:
#	- sleep
#	- "1000"

#파일을 manifest 디럭터리로 이동
mv static-busybox.yaml /etc/kubernetes/manifest

 

▶ 검증

#pod 확인
k get pods

#command sleep 1000 확인
k describe static-busybox-controlplane

 


08. Create a POD in the finance namespace named temp-bus with the image redis:alpine .

문제 유형 : 파드 생성 + 정해진 네임스페이스

더보기

▶ 과정

k run temp-bus --image=redis:alpine --n finance

 

▶ 검증

#naemspace finance에 파드가 동작 중인지 확인
k get pod -n finance

#namespace finance에 있는 temp-bus라는 파드의 상세정보 확인 -> 이미지
k describe pod temp-bus -n finance

 


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

문제 유형 : 오류 수정 + Init:CrashLoopBackOff

더보기

▶ 과정

#문제확인
k get pods
#Init:CrashLoopBackOff => Init컨테이너의 문제

#문제파드의 상세정보
k describe pod orange
#Init Containers:
#	State:	Waiting
#		Reason:	CrashLoopBackOff
#		~
#Containers:
#	orange-container:
#		~
#		State:	Waiting
#			Reson: PodInitializing
#		Ready: False

#log 확인해보기
k logs orange init-myservice
#sh: sleeeep: not found
#=> k describe pod orange에서 init containers의 Command를 확인해보면
#Command:
#	sh
#	-c
#	sleeep 2;
#라고 되어 있음 명령어 오류

#오류 수정
k edit pod orange
#위의 잘못된 명령어를 수정
#주의사항! : 종료저장(:q!)

#기존 포드 삭제 후 다시 생성
k replace --force -f yaml파일경로

 

▶ 검증

#검증
k get pods

 


⭐⭐10. Expose the hr-web-app as service hr-web-app-service application on port 30082 on the nodes on the cluster .
  The web application listens on port 8080.

문제 유형 : 노드포트 서비스 생성 + 정해진 포트

더보기

▶ 과정

#deploy 확인
k get deploy

#서비스 생성(expose)
k expose deploy hr-web-app --name=hr-web-service --type NodePort --port 8080
#서비스 확인
k get svc

#노드포트 서비스로 변경
k edit svc hr-web-service
#vi편집기의 nodeport를 임의의 포트가 아닌 30082로 변경

 

▶ 검증

#수정된 svc확인
k get svc

#서비스 리소스 변경시 재배포나 재시작을 필요로 하지 않음
Run the command: 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 to generate a service definition file.

Now, in generated service definition file add the nodePort field with the given port number under the ports section and create a service.

controlplane ~ ✖ kubectl expose deployment hr-web-app --type=NodePort --port=8080 --name=hr-we
b-app-service --dry-run=client -o yaml > hr-web-app-service.yaml

controlplane ~ ➜  ls
hr-web-app-service.yaml  pv.yaml  sample.yaml

controlplane ~ ➜  k create -f hr-web-app-service.yaml 
service/hr-web-app-service created

controlplane ~ ➜  cat hr-web-app-service.yaml 
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    app: hr-web-app
  name: hr-web-app-service
spec:
  ports:
  - port: 8080
    protocol: TCP
    targetPort: 8080
  selector:
    app: hr-web-app
  type: NodePort
status:
  loadBalancer: {}

controlplane ~ ➜  k get svc
NAME                 TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
hr-web-app-service   NodePort    10.107.128.246   <none>        8080:31880/TCP   40s
kubernetes           ClusterIP   10.96.0.1        <none>        443/TCP          160m
messaging-service    ClusterIP   10.104.98.39     <none>        6379/TCP         47m

controlplane ~ ➜  k edit svc hr-web-app-service 
service/hr-web-app-service edited

controlplane ~ ➜

⭐11. Use JSON PATH query to retrieve the osImages of all the nodes and store it in a file /opt/outputs/nodes_os_x43kj56.txt .
  The osImages are under the nodeInfo section under status of each node.

문제 유형 : JSON Path 쿼리 + 모든 노드의 os 이미지 검색 + 파일저장

더보기

▶ 과정

#os 이미지는 노드정보 섹션 아래에 있다고 명시되어있음
#노드 확인
k get no

#JSON포맷으로 확인
k get no -o JSON

#os 이미지 추출 -> 노드 정보섹션에서
k get no -o JSON
#맨 아래쪽으로 내리다 보면 nodeInfo가 있음
#nodeInfo는 Status 아래에 있음
#"nodeInfo": {
#	~
#	"osImage":	"Unbuntu 18.04.5 LTS"

#selector 공식문서 참고
# Get the version label of all pods with label app=cassandra
kubectl get pods --selector=app=cassandra -o \
  jsonpath='{.items[*].metadata.labels.version}'
  
#selector를 참고하여 osImage를 추츨
k get nodes -o jsonpath='{.items[*].status.nodeInfo.osImage}'

#파일로 리다이렉션하기
k get nodes -o jsonpath='{.items[*].status.nodeInfo.osImage}' > /opt/outputs/nodes_os_x43kj56.txt

 

▶ 검증

#리다이렉션한 파일 확인
cat /opt/outputs/nodes_os_x43kj56.txt

 


⭐12. Create a Persistent Volume with the given specification.
  - Volume Name : pv-analytics
  - Storage : 100Mi
  - Access modes : ReadWriteMany
  - Host Path : /pv/data-analytics

문제 유형 : 볼륨 생성

더보기

▶ 과정

#persistent 공식문서 검색
#첫번째 문서 들어가서 persistant volumes의 템플릿 확인

#pv.yaml 생성
#apiVersion: v1
#kind: PersistentVolume
#metadata:
#  name: pv-analytics
#spec:
#  capacity:
#    storage: 100Mi
#지정 안되어있는 부분 과감히 빼기
#  accessModes:
#    - ReadWriteMany
#다음의 내용은 문제에서 지정했으니 추가작업
#  hostPath:
#	 path: /pv/data-analytics

#pv생성
k create -f pv.yaml

 

▶ 검증

#생성 확인
k get pv

#호스트 경로 확인
k describe pv pv-analytics
#Source:
#	~
#	Path: /pv/data-analytics

 

728x90

'Cloud > CKA' 카테고리의 다른 글

[CKA] Mock Test - 사용자 생성 및 롤 바인딩 ( CSR , Rolebinding )  (0) 2024.06.25
Mock test Study Logs  (1) 2024.06.10
Mock Test 3  (0) 2024.05.13
Mock Test 2  (0) 2024.05.06
Practice Tests - 1. Core Concepts  (0) 2024.02.18

+ Recent posts