본문 바로가기
cloud/k8s(문제풀이)

[k8s]kodekloud-Persistent volume Claims

by mozi2 2022. 7. 5.
반응형

1.We have deployed a POD. Inspect the POD and wait for it to start running.

  In the current(default) namespace.

k get pods 

A) okay

 

2.The application stores logs at location /log/app.log. View the logs.

You can exec in to the container and open the file:

  kubectl exec webapp -- cat /log/app.log

kubectl exec webapp -- cat /log/app.log

3. If the POD was to get deleted now, would you be able to view these logs.

 삭제 한 뒤의 로그는 볼 수 없다. 

 

A) NO

 

4.Configure a volume to store these logs at /var/log/webapp on the host. Use the spec provided below.

  • Name: webapp

  • Image Name: kodekloud/event-simulator

  • Volume HostPath: /var/log/webapp

  • Volume Mount: /log

첫번째,  시도

 : 기존 webapp 파일을 다시 yaml파일로 만들어 수정후 적용하려고 햇으나.

 : 위와 같은 에러 발생 

 : 해결 방법은 같은 이름의 pod를 생성하려고 했기에 발생한 에러 이슈

 : 결론) webapp 파드를 삭제하고 진행하니 해결 완료 

 

2) 1번 시도 이후

 : 파드를 삭제한 이후 적용을 했으나 

 : 또다른 에러가 발생해 kodekloud 의 solution 을 참고해 container.volumeMounts 의 이름을 변경했으나.. 

: 또또 다른 에러가 발생함.

3) volume Mount 문제 

 : volumeMount 이름이 또 잘못됫단다..

 : 머야 대체...

4) 결국... 그냥 새로 yaml 파일 만들어서 ..

: 그랬더니 됫어.. 왜.. 기존은 안됫을가.. 왜 pod 생성이 안됫을가..

 

5) 3번 시도를 했던 name 을 지웠더니 잘 생성됨...

: 다시 한번 해볼 필요 있음 !! 

 

두번째 방법, 기존 yaml 파일 활용해서 하기 

1) 선택지에서 확인되는 부분만 수정하기

2) 기존 webapp 파드를 지우고 재생성 필요 

 

3) volumeMounts 이름과 volumes 이름을 동일하게 다른 이름으로 만들 것  

 

 

5. Create a Persistent Volume with the given specification.

  • Volume Name: pv-log

  • Storage: 100Mi

  • Access Modes: ReadWriteMany

  • Host Path: /pv/log

  • Reclaim Policy: Retain
vi pv-log.yaml
k apply -f pv-log.yaml
k get persistententvolume

https://kubernetes.io/docs/concepts/storage/persistent-volumes/

 

Persistent Volumes

This document describes persistent volumes in Kubernetes. Familiarity with volumes is suggested. Introduction Managing storage is a distinct problem from managing compute instances. The PersistentVolume subsystem provides an API for users and administrator

kubernetes.io

 

6. Let us claim some of that storage for our application. Create a Persistent Volume Claim with the given specification.

  • Volume Name: claim-log-1

  • Storage Request: 50Mi

  • Access Modes: ReadWriteOnce

vi claim-log-1
k apply -f claion-log-1.yaml

7. What is the state of the Persistent Volume Claim?

k get persistentvolume
k descrive persistentvolume
k get pvc

A) pending

 

8. What is the state of the Persistent Volume ?

A) Available

 

9. Why is the claim not bound to the available Persistent Volume?

 

??

A) Access Modes Mismatch

 

10. Update the Access Mode on the claim to bind it to the PV.

Delete and recreate the claim-log-1.

  • Volume Name: claim-log-1

  • Storage Request: 50Mi

  • PVol: pv-log

  • Status: Bound

k get pvc
k delete pvc claim-log-1
vi claim-log-1
k apply -f claim-log-1

: accessMode:

   - ReadWriteMany ---->>> Status 가 Bound 로 변경됨

 

11. You requested for 50Mi, how much capacity is now available to the PVC?

k get pvc

A) 100Mi

 

12.Update the webapp pod to use the persistent volume claim as its storage.

Replace hostPath configured earlier with the newly created PersistentVolumeClaim.

  • Name: webapp

  • Image Name: kodekloud/event-simulator

  • Volume: PersistentVolumeClaim=claim-log-1

  • Volume Mount: /log
k edit pod webapp
k delete pod webapp
k apply -f /tmp/kubectl-edit-4292738623.yaml

 

13. What is the Reclaim Policy set on the Persistent Volume pv-log?

k get pv

A) Retain

 

14.  What would happen to the PV if the PVC was destroyed?

 

A) The PV is not deleted but not available

 

15.Try deleting the PVC and notice what happens.

If the command hangs, you can use CTRL + C to get back to the bash prompt OR check the status of the pvc from another terminal

kubectl delete claim-log-1

 

A) The PVC is stuck in 'terminating' state

 

16. Why is the PVC stuck in Terminating state?

 

A) The pvc is being used by a POD

 

17.Let us now delete the webapp Pod.

Once deleted, wait for the pod to fully terminate.

  • Name: webapp
k delete pods webapp

 

18. What is the state of the PVC now?

kubectl get pvc

A) Deleted

 

19. What is the state of the Persistent Volume now?

kubectl get pv

A) Released

 

 

728x90
반응형

'cloud > k8s(문제풀이)' 카테고리의 다른 글

[k8s]Networking-Explore Environment  (0) 2022.08.01
[k8s]Kodekloud-storageClasses  (0) 2022.08.01
[cka] kodekloud-Network Policies  (0) 2022.07.01
[cka]kodekloud-security contexts  (0) 2022.07.01
[cka]kodekloud-Image Security  (0) 2022.06.29