본문 바로가기
CKA

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

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

 

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

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

 

 

13.

Create a Pod called redis-storage with image: redis:alpine with a Volume of type emptyDir 

that lasts for the life of the Pod.

Specs on the below.
Pod named 'redis-storage' created
Pod 'redis-storage' uses Volume type of emptyDir
Pod 'redis-storage' uses volumeMount with mountPath = /data/redis

 

참고 : https://kubernetes.io/docs/concepts/storage/volumes/#emptydir

 

command를 사용하여 간단하게 yaml 파일을 생성한다.

k run redis-storage --image=redis:alpine $do > redis-storage.yaml

 

생성 된 redis-storage.yaml 은 아래와 같다.

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: redis-storage
  name: redis-storage
spec:
  containers:
  - image: redis:alpine
    name: redis-storage
    resources: {}  # 삭제 부분
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}  # 삭제 부분

 

불필요한 내용은 삭제 후, empty 디렉터리를 사용하는 형태로 구성해 준다.

volume 이름의 경우 임의로 설정 가능하며, 용량을 할당하지 않아도 된다.

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: redis-storage
  name: redis-storage
spec:
  containers:
  - image: redis:alpine
    name: redis-storage
    volumeMounts:  # 추가된 부분
    - mountPath: /data/redis
      name: temp-volume
  volumes:
  - name: temp-volume
    emptyDir: {} # 추가된 부분
k apply -f redis-storage.yaml

 

 

 

 

14.

Create a new pod called super-user-pod with image busybox:1.28. 

Allow the pod to be able to set system_time.
The container should sleep for 4800 seconds.
Pod: super-user-pod
Container Image: busybox:1.28
Is SYS_TIME capability set for the container?

 

참고 : https://kubernetes.io/docs/tasks/configure-pod-container/security-context/

 

command를 사용하여 간단하게 yaml 파일을 생성한다.

k run super-user-pod --image=busybox:1.28 $do > super-user-pod.yaml

 

생성 된 super-user-pod.yaml 은 아래와 같다.

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: super-user-pod
  name: super-user-pod
spec:
  containers:
  - image: busybox:1.28
    name: super-user-pod
    resources: {}  # 삭제 부분
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}  # 삭제 부분

 

불필요한 내용은 삭제 후, 4800초 후에 sleep 할 수 있도록 command 추가

securityContext를 sys_time으로 설정 해준다.

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: super-user-pod
  name: super-user-pod
spec:
  containers:
  - image: busybox:1.28
    name: super-user-pod
    command: [ "sh", "-c", "sleep 4800" ]  # 추가된 부분
    securityContext:
      capabilities:
        add: ["SYS_TIME"]  # 추가된 부분
k apply -f super-user-pod.yaml

 

 

15.

A pod definition file is created at /root/CKA/use-pv.yaml. 

Make use of this manifest file and mount the persistent volume called pv-1. 

Ensure the pod is running and the PV is bound.
mountPath: /data
persistentVolumeClaim Name: my-pvc
persistentVolume Claim configured correctly
pod using the correct mountPath
pod using the persistent volume claim?

 

참고 : https://kubernetes.io/docs/concepts/storage/persistent-volumes/#persistentvolumeclaims

 

현재, pv-1이 존재하는 것을 확인, pvc는 현재 확인 되지 않는다.

my-pvc.yaml 생성

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-pvc
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
       storage: 10Mi

 

 

생성 되어 있는 use-pv.yaml 파일은 아래와 같다.

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: use-pv
  name: use-pv
spec:
  containers:
  - image: nginx
    name: use-pv
    resources: {}  # 삭제 부분
  dnsPolicy: ClusterFirst 
  restartPolicy: Always 
status: {}  # 삭제 부분

 

참고 : https://kubernetes.io/docs/concepts/storage/persistent-volumes/#claims-as-volumes

 

pod에 volume, volumeclaim을 연결해준다. 

이름은 volmeMounts 와 volumes 동일하게 설정해주며, 생성한 pvc 의 이름을 넣어준다.

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: use-pv
  name: use-pv
spec:
  containers:
  - image: nginx
    name: use-pv
    volumeMounts:  # 추가된 부분
    - mountPath: "/data"
      name: mypd
  volumes:
    - name: mypd
      persistentVolumeClaim:
        claimName: my-pvc  # 추가된 부분

 

 

16.

Create a new deployment called nginx-deploy, with image nginx:1.16 and 1 replica. 

Next upgrade the deployment to version 1.17 using rolling update.
Deployment : nginx-deploy. Image: nginx:1.16
Image: nginx:1.16
Task: Upgrade the version of the deployment to 1:17
Task: Record the changes for the image upgrade

 

참고 : https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#rolling-back-a-deployment

 

command를 사용하여 간단하게 생성해준다.

 k create deployment nginx-deploy --image=nginx:1.16 --replicas=1

k set image deployment/nginx-deploy nginx=nginx:1.7

 

k get rs | grep nginx

 

17.

craete Role, Rolebinding for developer

developer should have permission to create, list, get, update and delete pods in the development namespace . 

 

참고 : https://kubernetes.io/docs/reference/access-authn-authz/certificate-signing-requests/

 

namespace를 생성해준다.

k create ns development

 

k create role developer --resource=pod --verb=create,list,get,update,delete --namespace=development

k create rolebinding developer-role-binding --role=developer --user=developer --namespace=development

 

 

18.

Create a nginx pod called nginx-resolver using image nginx, expose it internally with a service called nginx-resolver-service. Test that you are able to look up the service and pod names from within the cluster. Use the image: busybox:1.28 for dns lookup. Record results in /root/CKA/nginx.svc and /root/CKA/nginx.pod

Pod: nginx-resolver created
Service DNS Resolution recorded correctly
Pod DNS resolution recorded correctly

 

command를 사용하여 간단하게 생성해준다.

k run nginx-resolver --image=nginx

k expose pod nginx-resolver --name=nginx-resolver-service --port=80 --target-port=80 --type=ClusterIP

 

확인을 위해 busybox를 이용하여 검토해준다. 이때 한 번만 사용하고 삭제할 예정이기 때문에 "--rm --restart=Never" 옵션을 추가해준다.

k  run test-nslookup --image=busybox:1.28 --rm -it --restart=Never -- nslookup nginx-resolver-service > /root/CKA/nginx.svc

k get pod -o wide

k run test-nslookup --image=busybox:1.28 --rm -it --restart=Never -- nslookup 198.18.0.185

 

 

 

19.

Create a static pod on node01 called nginx-critical with image nginx and make sure that it is recreated/restarted automatically in case of a failure.

 

Use /etc/kubernetes/manifests as the Static Pod path for example.
static pod configured under /etc/kubernetes/manifests ?
Pod nginx-critical-node01 is up and running

 

command를 사용해 간단하게 yaml 파일을 생성한다.

k run nginx-critical --image=nginx --dry-run=client -o yaml > static.yaml

 

 

생성한 yaml 파일을 워커 노드 시작시 자동으로 실행되는 "/etc/kubernetes/manifests" 폴더에 넣어준다.

 

현재 pod는 생성되어 있지 않지만, 위 워커노드 manifestes 폴더에 yaml 파일을 저장하면, 자동으로 생성된다.

'CKA' 카테고리의 다른 글

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