본문 바로가기
CKA

[CKA] 연습문제 정리 2탄!

by 싱숭생숭늉 2024. 8. 8.

 

해당 연습문제는 유데미 강의를 바탕으로 작성했다.

https://www.udemy.com/course/certified-kubernetes-administrator-with-practice-tests/?couponCode=ST10MT8624

 

문제를 풀때 https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands

해당 경로를 많이 사용하고 많이 참고 했다.

 

시험 시간이 넉넉하지는 않았다 그래서 타이핑 시간과 삭제시간(pod 잘 못 생성시 삭제가 필요)을 줄이기 위해 아래 명령어를 사용했다. (https://peterica.tistory.com/540 피터님이 알려주신 좋은 꿀팁!)

# "kubectl"를 "k"약자로 변경
alias k=kubectl
# yaml파일과 문법이 정상적으로 작동하는 지 확인
export do="--dry-run=client -o yaml" # k create deploy nginx --image=nginx $do
# pod삭제 시 바로 삭제
export now="--force --grace=period 0" # k delete pod nginx $now

 

 

7.

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

k run --restart=Never --image=busybox static-busybox --dry-run=client -o yaml --command -- sleep 1000 > /etc/kubernetes/manifests/static-busybox.yaml

 

테스트 환경이 NKS(네이버 클라우드 kubernets 서비스)를 사용 하였다.

문제에서 요구하는 controlplane의 static pod 설정은 시험환경 내에 "/etc/kubernetes/manifests/static-busybox.yaml" 넣어줘야 한다.

는 일단 해당 문법이 올바른지 yaml로 확인 만 진행했다.

 

8.

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

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

k create ns finace
k run temp-bus --image=redis:alpine -n finace

 

9.

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

 

orange 파드가 현재 실행이 아닌것을 확인 할 수 있다.

 

k edit pod orange

 

 

command 부분에 sleeeep 2; 가 잘못된 것을 확인 할 수 있고 이를 sleep 으로 수정을 해준다.

 

 

이미 실행중이기 때문에 해당 edit으로는 수정이 불가능 하다.

그러면 kubelet이 임시 폴더에 해당 스크립트를 저장해 준다.

 

 

 k replace -f kubectl-edit-1229811559.yaml --force

 

이미 실행 중이기 때문에 강제로 교체가 필요하다! 그러므로 옵션 "--force" 가 필수적으로 들어가야 한다.

 

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.

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

 

일단 command를 사용하여 NodePort를 type의 service를 생성해준다.

 

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
    nodePort: 30082
  selector:
    app: hr-web-app
  type: NodePort
status:
  loadBalancer: {}

 

nodeport를 추가해준다. 30082로 받기로 했으니깐! 만약 nodeport 부분을 지정하지 않고 생성하게 되면 임의의 port를 부여하게 된다.

 

그러므로 nodeport를 지정해줘서 작업해야 한다.

 

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.

k get nodes -o jsonpath='{.items[*].status.nodeInfo.osImage}' > /opt/outputs/nodes_os_x43kj56.txt

 

12.

Create a Persistent Volume with the given specification: -
Volume name: pv-analytics
Storage: 100Mi
Access mode: ReadWriteMany
Host path: /pv/data-analytics

참고 : https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/#create-a-persistentvolume

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-analytics
spec:
  capacity:
    storage: 100Mi
  accessModes:
    - ReadWriteMany
  hostPath:
    path: /pv/data-analytics

 

'CKA' 카테고리의 다른 글

[CKAD] 연습문제 정리 5탄!!  (0) 2024.08.22
[CKAD] 연습문제 정리 4탄!  (0) 2024.08.21
[CKA] 연습문제 정리 3탄!  (0) 2024.08.14
[CKA] 연습문제 정리 1탄!  (0) 2024.08.07
[CKA] 자격증 준비  (0) 2024.08.07