StorageClass

In Chapter 2, Walking through Kubernetes Concepts, we learned how to declare PersistentVolume and PersistentVolumeClaim. With dynamic provisioning, you can define a set of StorageClass with different physical storage backends and use them in PersistentVolume or PersistentVolumeClaim. Let's see how it works.

To check the current default StorageClass, use kubectl get storageclasses command:

# kubectl get storageclasses
NAME PROVISIONER AGE
standard (default) kubernetes.io/gce-pd 1h

We can see we have a default storage class named standard and its provisioner is GCE PD.

Let's create a PersistentVolumeClaim request and use the standard StorageClass as the backend:

# cat gke-pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-example-pv
spec:
storageClassName: standard
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi

// create resources
# kubectl create -f gke-pvc.yaml
persistentvolumeclaim "pvc-example-pv" created

storageClassName is the place to put the name of the StorageClass. If you put in something that doesn't exist, PVC will not be created, since there is no proper mapped StorageClass to use:

// check pvc status
# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
pvc-example-pv Bound pvc-1491b08e-1cfc-11e8-8589-42010a800360 10Gi RWO standard 12m

// describe the details of created PVC
# kubectl describe pvc pvc-example-pv
Name: pvc-example-pv
Namespace: default
StorageClass: standard
Status: Bound
Volume: pvc-1491b08e-1cfc-11e8-8589-42010a800360
Labels: <none>
Annotations: pv.kubernetes.io/bind-completed=yes
pv.kubernetes.io/bound-by-controller=yes
volume.beta.kubernetes.io/storage-provisioner=kubernetes.io/gce-pd
Finalizers: []
Capacity: 10Gi
Access Modes: RWO
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ProvisioningSucceeded 12m persistentvolume-controller Successfully provisioned volume pvc-1491b08e-1cfc-11e8-8589-42010a800360 using kubernetes.io/gce-pd

We can see volume pvc-1491b08e-1cfc-11e8-8589-42010a800360 has been created and bounded. If we list GCP disks, we'll find there was a Persistent Disk created; the suffix of the disk name indicates the volume name in Kubernetes. That's the magic of dynamic volume provisioning:

# gcloud compute disks list
NAME ZONE SIZE_GB TYPE STATUS
gke-my-k8s-cluster-5ef-pvc-1491b08e-1cfc-11e8-8589-42010a800360 us-central1-a 10 pd-standard READY

Besides the default StorageClass, you can also create your own. Recap this in Chapter 2, Walking through Kubernetes Concepts.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.148.107.254