Kubernetes - Persistent Volume Claims đŠ
Description đ
Persistent Volume Claims, otherwise known as PVC, and Persistent Volumes are two separate Kubernetes resources. PVC are a way to dynamically provision from a persistent volume based on the request and properties set on the volume such as size, access mode, storage class, etc. PVC are also used to bind persistent volumes to pods and containers in order to persist data. PVC are also used to reclaim persistent volumes when they are no longer needed. Every PVC is bound to a single persistent volume. There is a 1:1 relationship between PVC and persistent volumes.
Basic Commands đ
- 
    
get
pvckubectl get pvc - 
    
delete
pvckubectl delete pvc <pvc-name>- but what happens to the underlying 
persistent volumeđ¤- 
            
by default the
persistent volumereclaim policy is set toretain, but can be changed todeleteorrecycle.# persistent volume reclaim policy can be set to delete, retain, or recycle # this is placed in the pv spec section persistentVolumeReclaimPolicy: Retain 
 - 
            
 
 - but what happens to the underlying 
 
Examples đ§Š
- 
    
persistent volume claimdefinitionapiVersion: v1 kind: PersistentVolumeClaim metadata: name: myclaim spec: accessModes: - ReadWriteOnce resources: requests: storage: 500Mi- similar to persistent volumes, accessMode can be 
ReadWriteOnce,ReadOnlyMany, orReadWriteMany 
 - similar to persistent volumes, accessMode can be 
 - 
    
use
persistent volume claimin apoddefinitionapiVersion: v1 kind: Pod metadata: name: mypod spec: containers: - name: myfrontend image: nginx volumeMounts: - mountPath: "/var/www/html" name: mypd volumes: - name: mypd persistentVolumeClaim: claimName: myclaimpersistent volume claimis defined in thevolumessection of thepoddefinitionpersistent volume claimis mounted to thepodin thevolumeMountssection of thepoddefinition
 - 
    
pvcfor use with examples in pv and volumes sectionapiVersion: v1 kind: PersistentVolumeClaim metadata: name: claim-log-1 spec: accessModes: - ReadWriteOnce resources: requests: storage: 50Mi- 
        
update
podfrom initial example to usepvcapiVersion: v1 kind: Pod metadata: name: webapp spec: containers: - name: event-simulator image: kodekloud/event-simulator env: - name: LOG_HANDLERS value: file volumeMounts: - mountPath: /log name: log-volume volumes: - name: log-volume persistentVolumeClaim: claimName: claim-log-1 
 -