k8s/CKA

Mock Exam - 1

부엉이사장 2024. 9. 6. 04:22

 

Summary
  • 이번엔 모의시험이기 때문에 yaml딱히 필요없는건 빨리 지나가도록 하겠음.
  • command다음에 --붙이는건 그 이후로 띄어쓰기 같이 포함하겠다임. 그래서 $samp를 앞에 써줘야함.
  • pod에 문제생기면 logs랑 describe 잘 확인하샘
export samp="--dry-run=client -o yaml"
export now="--force --grace-period 0"

$samp, $now붙은건 이 명령어로 약어만든거니까 주의


 

 

# 1    

pod만들라고 함

kubectl run nginx-pod --image nginx:alpine

 

 

- 검토

kubectl get pods
kubectl describe pod nginx-pod |$grep image

 

 

 

# 2

pod 만들래

kubectl run messaging --image redis:alpine --labels tier=msg

 

- 검토

kubectl get pods
kubectl describe pod messaging |$grep image
kubectl describe pod messaging |$grep label

 

혹은

kubectl get pods --show-labels

 

 

# 3

네임스페이스 만들래

kubectl create namespace apx-x9984574

 

 

- 검토

kubectl get namespaces |$grep apx-x9984574

 

 

 

 

# 4    이거 안풀어도될듯?

node 리스트를 json형식으로 파일만들어서 넣으래

kubectl get nodes -o json >/opt/outputs/nodes-z3444kd9.json

 

 

- 검토

vi /opt/outputs/nodes-z3444kd9.json

 

 

 

# 5

서비스를 만들래 messaging pod랑 연결해서..

 

kubectl expose pod messaging --name messaging-service --port 6379

 

 

- 검토

kubectl describe service messaging-service

 

 

 

# 6

deployment를 만들래

kubectl create deployment hr-web-app --image kodekloud/webapp-color --replicas 2

 

 

- 검토

kubectl get deployments.apps

 

kubectl describe deployments.apps hr-web-app

 

 

# 7

static pod를 만들래.

 

 

pod/ static pod & resource & 환경변수

## static pod 만들기 보통 마스터노드에서 컨테이너를 만들면 저렇게 api서버를 거쳐서 pod가 생성된다. 하지만 static pod는 워커 노드 자체에서 kubelet이 직접 pod를 만든다는 것이다. 즉 이 pod는 kublet

jacobowl.tistory.com

이건 예전에 포스팅했던 static pod 포스트임

 

일단 controlplane에다가 만들라고하니까 ssh로 node에 접근할 필요는 없음.

 

공식문서를 보면

 

 

Create static Pods

Static Pods are managed directly by the kubelet daemon on a specific node, without the API server observing them. Unlike Pods that are managed by the control plane (for example, a Deployment); instead, the kubelet watches each static Pod (and restarts it i

kubernetes.io

 

 

node의 특정경로에 해당 pod yaml 파일을 넣어주면 된다

/etc/kubernetes/manifests/

 

 

일단 현재 pod는 

이렇게 네개있음

 

yaml파일 부터 만들면,

kubectl run static-busybox --image busybox $samp --command -- sleep 1000 > static-busybox.yaml

들어가서 확인하면 

잘 되어있음. 난 혹시 > static-busybox.yaml도 있을줄 알고..

 

cp static-busybox.yaml /etc/kubernetes/manifests/

해당파일을 static pod 경로에 보내자.

 

잘 만들어짐

 

- 검토

static pod는 kublet에 의해 죽어도 다시 살아남

kubectl get pods
kubectl delete pod static-busybox-controlplane
kubectl get pods

지워도 살아나는걸 볼 수 있음.

 

 

# 8

finance ns에 pod를 만들래

 

kubectl run temp-bus --image redis:alpine -n finance

 

 

- 검토

kubectl get pods -n finance
kubectl describe pod temp-bus -n finance |$grep image

 

 

# 9     이거 안풀어도될듯? 근데 init container있어서 개념에는 도움됨.

orange 어플이 문제있는데 고치래

crashloopbackoff상태라고 함

kubectl logs pods/orange

음 모르겠음

kubectl describe pod orange

재시작 실패했는데 init-myservice컨테이너에서 fail떴음

kubectl edit pod orange

init-myservice라는 컨테이너의 command에 sleep을 늘여놨네

고치샘.

에러뜨는데 edit 한 yaml파일이 저 경로에 저장됐대.

저파일로 pod만들면댐

kubectl delete pod orange

먼저 pod지우고

kubectl apply -f /tmp/kubectl-edit-3584095314.yaml

 

 

- 검토

kubectl get pods

이제 잘 running함

 

 

 

따배씨 / pod - multi & side-car & init containers / resource usage

Introductionpod는 거의다 아는데 문제유형 훝고 몰랐던 자잘한거 정리하는 용도로 포스팅함.강의 여섯개인가 내용 싹다 걍 합쳐서 제목이 좀 괴랄하다.Summary리소스만들때 먼저 dry-run해주고 문제랑

jacobowl.tistory.com

init container 개념담은 포스팅

 

 

# 10

서비스를 만들래

hr-머시기가 디플로이먼트니까 deployment기준으로 expose해줘야할듯

 

복잡하니까 커맨드로 야믈따서 일단 보자

kubectl expose deployment hr-web-app --name hr-web-app-service --type NodePort --port 8080 $samp > hr-web-app-service.yaml

커맨드로 nodeport가 안붙어서 다큐먼트 보면.

 

Service

Expose an application running in your cluster behind a single outward-facing endpoint, even when the workload is split across multiple backends.

kubernetes.io

ports쪽에 nodeport 써주면 됨.

다른건 잘 적용됨.

kubectl apply -f hr-web-app-service.yaml

 

 

- 검토

kubectl get svc

 

 

 

- 실제 시험에선

이 문제는 그냥 직접 nodeport svc만드는거였는데 실제 시험에선 기존서비스를 nodeport로 업데이트하는거였음

kubectl expose svc 이런걸로했움

 

 

# 11      이거 풀지마! jsonpath문제

 

os이미지를 받기위한 json path를 사용해라.. 파일안에 저장해라.. 뭔소린지 모르겠음..

난 그냥 

kubectl get nodes -o jsonpath='{@}' |grep osImage

이거해서 뜨는거 텍스트 복붙해서 해당파일에 넣어줌

 

 

# 12

저런 persistent volume을 만들래

 

 

Persistent Volumes

This document describes persistent volumes in Kubernetes. Familiarity with volumes, StorageClasses and VolumeAttributesClasses is suggested. Introduction Managing storage is a distinct problem from managing compute instances. The PersistentVolume subsystem

kubernetes.io

공식문서에 yaml양식이 있음.

근데 host path쓰는곳을 모르겠네..

 

더 뒤져보니

 

Configure a Pod to Use a PersistentVolume for Storage

This page shows you how to configure a Pod to use a PersistentVolumeClaim for storage. Here is a summary of the process: You, as cluster administrator, create a PersistentVolume backed by physical storage. You do not associate the volume with any Pod. You,

kubernetes.io

이게있음.

저거 yaml따서

yaml파일 만들어줬음.

kubectl apply -f persistent-volume.yaml

ㄱㄱ

 

 

 

따배씨 / persistent volume

Introduction개념은 자세히 안적고 대충 persistent volume이랑 persistent volume claim, 이 둘을 사용하는 pod의 관계를 알아야 한다.간단한 테스트 코드를 직접 쳐보며 그림으로 설명하겠다. Summarypv, pvc, pod관

jacobowl.tistory.com

내 포스팅임

mock exam2에 4번에 pvc도 만들고 연결하는거도 나옴.