10.1. Persistent Volumes#
A persistent volume is allocated storage for Kubernetes applications. You as the user don’t directly create persistent volumes, you request them with a persistent volume claim. The Kubernetes system processes your PersistentVolumeClaim
and satisfies it by creating a PersistentVolume
.
The Resource#
Create the file deployment/pvc.yaml
with the following contents:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysite-data
spec:
resources:
requests:
storage: 1Gi
accessModes:
- ReadWriteOnce
Apply and Check the PVC#
Apply the PersistentVolumeClaim
resource:
$ kubectl apply -f pvc.yaml
Verify that the resource has been created:
Warning
On GKE the volume won’t be bound until a Pod asks for it. Just move on to the next lab and come back when your pod is applied.
$ kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
db Bound pvc-aa5c22d9-8251-4d44-b71f-e6a290b92aec 1Gi RWO standard 123m
Check the corresponding PersistentVolume
resource:
$ kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pvc-aa5c22d9-8251-4d44-b71f-e6a290b92aec 1Gi RWO Delete Bound default/db standard 123m
The resource name is automatically generated. You can examine the resource with this command:
Note
Change the name of the pvc to match yours.
$ kubectl describe pv/pvc-aa5c22d9-8251-4d44-b71f-e6a290b92aec
Name: pvc-aa5c22d9-8251-4d44-b71f-e6a290b92aec
Labels: <none>
Annotations: hostPathProvisionerIdentity: 04bedfd4-c332-4433-a681-b0fa67f97752
pv.kubernetes.io/provisioned-by: k8s.io/minikube-hostpath
Finalizers: [kubernetes.io/pv-protection]
StorageClass: standard
Status: Bound
Claim: default/db
Reclaim Policy: Delete
Access Modes: RWO
VolumeMode: Filesystem
Capacity: 1Gi
Node Affinity: <none>
Message:
Source:
Type: HostPath (bare host directory volume)
Path: /tmp/hostpath-provisioner/default/db
HostPathType:
Events: <none>
What provisioner was used?