Skip to content

Latest commit

 

History

History
90 lines (64 loc) · 2.38 KB

08-Persistent-Volume-Claims.md

File metadata and controls

90 lines (64 loc) · 2.38 KB

Persistent Volume Claims

In this section, we will take a look at Persistent Volume Claim

  • Now we will create a Persistent Volume Claim to make the storage available to the node.
  • Volumes and Persistent Volume Claim are two separate objects in the Kubernetes namespace.
  • Once the Persistent Volume Claim created, Kubernetes binds the Persistent Volumes to claim based on the request and properties set on the volume.

class-17

  • If properties not matches or Persistent Volume is not available for the Persistent Volume Claim then it will display the pending state.
pvc-definition.yaml

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: myclaim
spec:
  accessModes: [ "ReadWriteOnce" ]
  resources:
   requests:
     storage: 1Gi
pv-definition.yaml

kind: PersistentVolume
apiVersion: v1
metadata:
    name: pv-vol1
spec:
    accessModes: [ "ReadWriteOnce" ]
    capacity:
     storage: 1Gi
    hostPath:
     path: /tmp/data

Create the Persistent Volume

$ kubectl create -f pv-definition.yaml
persistentvolume/pv-vol1 created

$ kubectl get pv
NAME      CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM   STORAGECLASS   REASON   AGE
pv-vol1   1Gi        RWO            Retain           Available                                   10s

Create the Persistent Volume Claim

$ kubectl create -f pvc-definition.yaml
persistentvolumeclaim/myclaim created

$ kubectl get pvc
NAME      STATUS    VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS   AGE
myclaim   Pending                                                     35s

$ kubectl get pvc
NAME      STATUS   VOLUME    CAPACITY   ACCESS MODES   STORAGECLASS   AGE
myclaim   Bound    pv-vol1   1Gi        RWO                           1min

Delete the Persistent Volume Claim

$ kubectl delete pvc myclaim

Delete the Persistent Volume

$ kubectl delete pv pv-vol1

Kubernetes Persistent Volume Claims Reference Docs