클라우드/쿠버네티스

[Kubernetes] 17. 쿠버네티스 PV(Persistent Volume) 및 PVC(Persistent Volume Claim)

윤창이 2023. 4. 23. 17:51
728x90

[주의] 개인 공부를 위해 쓴 글이기 때문에 주관적인 내용은 물론, 쓰여진 정보가 틀린 것일 수도 있습니다!

피드백 부탁드립니다. (- -)(_ _) 꾸벅

 

 


 


[ PV 실습 ]

Question : Create Persistent Volume

TASK :
Create a persistent volume whith name app-config of capacity 1Gi and access mode ReadWriteMany. StorageClass: az-c The Type of volume is hostPath and its location is /root/cka_pvc_test.

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

 

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

$ vi pv_cka.yaml
    
apiVersion: v1
kind: PersistentVolume
metadata:
  name: app-config
spec:
  storageClassName: az-c
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteMany
  hostPath:
    path: "/root/cka_pvc_test"
$ kubectl apply -f pv_cka.yaml
persistentvolume/app-config created\

$ kubectl get pv
NAME         CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM   STORAGECLASS   REASON   AGE
app-config   1Gi        RWX            Retain           Available           az-c

 

 


[ PVC 실습 ]

Question : Application with PersistentVolumeClaim

TASK 1 :
Create a new PersistentVolumeClaim

  • Name : app-volume
  • StorageClass : az-c
  • Capacity : 10Mi


TASK 2 :
Create a new Pod which mounts the PersistentVolumeClaim as a volume

  • Name : web-server-pod
  • Image : nginx
  • Mount path : /usr/share/nginx/html

TASK 3 :
Configure the new Pod to have ReadWriteMany access on the volume.

 

 

Task 1

$ vi pvc_cka.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: app-volume
spec:
  storageClassName: az-c
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Mi
      
$ kubectl apply -f pvc_cka.yaml

 

 

# 같은 Storage Class Name을 가진 PV가 PVC에 할당된다
yoon@master:~$ kubectl get pvc
NAME         STATUS   VOLUME       CAPACITY   ACCESS MODES   STORAGECLASS   AGE
app-volume   Bound    app-config   1Gi        RWX            az-c           4s
yoon@master:~$ kubectl get pv
NAME         CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                STORAGECLASS   REASON   AGE
app-config   1Gi        RWX            Retain           Bound    default/app-volume   az-c                    18m

 

Task 2

$ vi web_server_pod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: web-server-pod
spec:
  volumes:
    - name: web-volume
      persistentVolumeClaim:
        claimName: app-volume
  containers:
    - name: web-server-pod
      image: nginx
      ports:
        - containerPort: 80
          name: "http"
      volumeMounts:
        - mountPath: "/usr/share/nginx/html"
          name: web-volume
          
$ kubectl apply -f web_server_pod.yaml

 

Task 3

$ kubectl edit pv app-config
...
spec:
  accessModes:
  - ReadWriteMany
...
728x90