새소식

Recent Study/udemy - CKA with Practice Tests

KodeKloud - Test Record (section 8)

  • -

1. The application stores logs at location /log/app.log. View the logs. You can exec in to the container and open the file:

> k exec webapp -- cat /log/app.log

 

 

2. 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 

> k edit pod webapp

> k replcae --force -f /tmp/kubectl-edit-1845071691.yaml

 

============================================================ 

terminationMessagePolicy: File
    volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: kube-api-access-2p9wt
      readOnly: true
    - mountPath: /log
      name: log-volume

 

volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: kube-api-access-2p9wt
      readOnly: true
    - mountPath: /log
      name: log-volume

============================================================

 

 

3. 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.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-log
spec:
  capacity:
    storage: 100Mi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  hostPath:
    path: /pv/log

 

> k create -f pv.yaml

 

 

4. 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 pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: claim-log-1
spec:
  accessModes:
    - ReadWriteOnce
  volumeMode: Filesystem
  resources:
    requests:
      storage: 50Mi

> k create -f pvc.yaml

 

 

5. Update the Access Mode on the claim to bind it to the PV. Delete and recreate the claim-log-1.

AccessMode 불일치로, pvc의 AccessMode를 수정. ReadWriteOnce -> ReadWriteMany

 

> vi pvc.yaml

> k replace --force -f pvc.yaml

 

 

6. 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

 

  volumes:
  - persistentVolumeClaim:
      claimName: claim-log-1
    name: log-volume

 

> k replace --force -f /tmp/kubectl-edit-2628926476.yaml

 

 

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

> k get pv pv-log

 

 

실행 중인 Pod가 PVC, PV를 사용 중:

  • Pod는 데이터를 저장하기 위해 PVC를 사용하고 있습니다. PVC는 실제 스토리지를 제공하는 PV에 바인딩되어 있습니다.
  1. PVC 삭제 시:
    • PVC를 삭제하면, 쿠버네티스는 해당 PVC에 바인딩된 PV를 관리해야 합니다. 그러나 PVC가 사용 중일 때는 바로 삭제되지 않고 Terminating 상태로 남게 됩니다. 이는 PVC를 사용하는 Pod가 아직 실행 중이기 때문입니다. Pod가 해당 PVC에 접근하고 있으므로, 안전하게 삭제되기 위해서는 먼저 Pod의 사용이 중단되어야 합니다.
  2. Pod 삭제 시:
    • Pod가 삭제되면, Pod는 더 이상 PVC를 사용하지 않게 됩니다. 이로 인해 PVC도 더 이상 사용되지 않으므로, PVC의 삭제가 완료될 수 있습니다.
    • PVC가 삭제되면, 해당 PVC에 바인딩된 PV는 Released 상태가 됩니다. Released 상태는 PV가 더 이상 특정 PVC에 바인딩되어 있지 않음을 나타내며, PV의 데이터는 여전히 존재하지만, 새로운 PVC가 이 PV를 다시 사용하기 전에 PV는 정리되어야 할 수 있습니다.

이 과정에서 중요한 점은 쿠버네티스가 데이터의 일관성과 안전성을 유지하기 위해 PVC와 PV의 상태를 관리한다는 것입니다. PVC가 사용 중일 때는 쉽게 삭제되지 않도록 하고, PVC가 더 이상 사용되지 않을 때에만 삭제 및 PV의 상태 변경이 이루어집니다.

 

 

'Recent Study > udemy - CKA with Practice Tests' 카테고리의 다른 글

KodeKloud - Test Record (section 9)  (0) 2024.08.02
Section 9 : Networking  (0) 2024.07.28
Section 8 : Storage  (0) 2024.07.20
KodeKloud - Test Record (section 7)  (2) 2024.07.12
Section 7 : Security  (0) 2024.07.12
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.