This guide provides the steps necessary to enable binding of persistent volume claims (PVCs) to persistent volumes (PVs) via selector and label attributes. By implementing selectors and labels, regular users are able to target provisioned storage by identifiers defined by a cluster administrator.
In cases of statically provisioned storage, developers seeking persistent storage are required to know a handful identifying attributes of a PV in order to deploy and bind a PVC. This creates several problematic situations. Regular users might have to contact a cluster administrator to either deploy the PVC or provide the PV values. PV attributes alone do not convey the intended use of the storage volumes, nor do they provide methods by which volumes can be grouped.
Selector and label attributes can be used to abstract away PV details from the user while providing cluster administrators a way of identifying volumes by a descriptive and customizable tag. Through the selector-label method of binding, users are only required to know which labels are defined by the administrator.
Note
|
The selector-label feature is currently only available for statically provisioned storage and is currently not implemented for storage provisioned dynamically. |
This section reviews how to define and deploy PVCs.
-
A running {product-title} 3.3+ cluster
-
A volume provided by a supported storage provider
-
A user with a cluster-admin role binding
-
As the cluser-admin user, define the PV. For this example, we will be using a GlusterFS volume. See the appropriate storage provider for your provider’s configuration.
Example 1. Persistent Volume with LabelsapiVersion: v1 kind: PersistentVolume metadata: name: gluster-volume labels: (1) volume-type: ssd aws-availability-zone: us-east-1 spec: capacity: storage: 2Gi accessModes: - ReadWriteMany glusterfs: endpoints: glusterfs-cluster path: myVol1 readOnly: false persistentVolumeReclaimPolicy: Recycle
-
A PVC whose selectors match all of a PV’s labels will be bound, assuming a PV is available.
-
-
Define the PVC:
Example 2. Persistent Volume Claim with SelectorsapiVersion: v1 kind: PersistentVolumeClaim metadata: name: gluster-claim spec: accessModes: - ReadWriteMany resources: requests: storage: 1Gi selector: (1) matchLabels: (2) volume-type: ssd aws-availability-zone: us-east-1
-
Begin selectors section.
-
List all labels by which the user is requesting storage. Must match all labels of targeted PV.
-
As the cluster-admin user, create the persistent volume:
# oc create -f gluster-pv.yaml persistentVolume "gluster-volume" created # oc get pv NAME LABELS CAPACITY ACCESSMODES STATUS CLAIM REASON AGE gluster-volume map[] 2147483648 RWX Available 2s
Once the PV is created, any user whose selectors match all its labels can create their PVC.
# oc create -f gluster-pvc.yaml persistentVolumeClaim "gluster-claim" created # oc get pvc NAME LABELS STATUS VOLUME gluster-claim Bound gluster-volume