9.1. Request Storage for Your Application#

A persistent volume is storage that is allocated by Kubernetes for use in your application. You 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 deployment/pvc.yaml

Verify that the resource has been created:

Note

On GKE the volume won’t be bound until a Pod asks for it. In the next lab you’ll update your pod definition.

$ kubectl get pvc
NAME          STATUS    VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS   VOLUMEATTRIBUTESCLASS   AGE
mysite-data   Pending                                      standard-rwo   <unset>                 20s

Check the corresponding PersistentVolume resource:

$ kubectl get pv 
No resources found

It’ll appear when it’s needed.