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
pvc
kubectl get pvc
-
delete
pvc
kubectl delete pvc <pvc-name>
- but what happens to the underlying
persistent volume
đ¤-
by default the
persistent volume
reclaim policy is set toretain
, but can be changed todelete
orrecycle
.# 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 claim
definitionapiVersion: 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 claim
in apod
definitionapiVersion: v1 kind: Pod metadata: name: mypod spec: containers: - name: myfrontend image: nginx volumeMounts: - mountPath: "/var/www/html" name: mypd volumes: - name: mypd persistentVolumeClaim: claimName: myclaim
persistent volume claim
is defined in thevolumes
section of thepod
definitionpersistent volume claim
is mounted to thepod
in thevolumeMounts
section of thepod
definition
-
pvc
for use with examples in pv and volumes sectionapiVersion: v1 kind: PersistentVolumeClaim metadata: name: claim-log-1 spec: accessModes: - ReadWriteOnce resources: requests: storage: 50Mi
-
update
pod
from initial example to usepvc
apiVersion: 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
-