Using Storage Classes for Existing Legacy Storage

You are viewing documentation for a release that is no longer supported. The latest supported version of version 3 is [3.11]. For the most recent version 4, see [4]

You are viewing documentation for a release that is no longer supported. The latest supported version of version 3 is [3.11]. For the most recent version 4, see [4]

Overview

In this example, a legacy data volume exists and a cluster-admin or storage-admin needs to make it available for consumption in a particular project. Using StorageClasses decreases the likelihood of other users and projects gaining access to this volume from a claim because the claim would have to have an exact matching value for the StorageClass name. This example also disables dynamic provisioning. This example assumes:

Scenario 1: Link StorageClass to existing Persistent Volume with Legacy Data

As a cluster-admin or storage-admin, define and create the StorageClass for historical financial data.

Example 1. StorageClass finance-history Object Definitions

  1. kind: StorageClass
  2. apiVersion: storage.k8s.io/v1
  3. metadata:
  4. name: finance-history (1)
  5. provisioner: no-provisioning (2)
  6. parameters: (3)
1Name of the StorageClass.
2This is a required field, but since there is to be no dynamic provisioning, a value must be put here as long as it is not an actual provisioner plug-in type.
3Parameters can simply be left blank, since these are only used for the dynamic provisioner.

Save the definitions to a YAML file (finance-history-storageclass.yaml) and create the StorageClass.

  1. # oc create -f finance-history-storageclass.yaml
  2. storageclass "finance-history" created
  3. # oc get storageclass
  4. NAME TYPE
  5. finance-history no-provisioning

cluster-admin or storage-admin users are responsible for relaying the correct StorageClass name to the correct users, groups, and projects.

The StorageClass exists. A cluster-admin or storage-admin can create the Persistent Volume (PV) for use with the StorageClass. Create a manually provisioned disk using GCE (not dynamically provisioned) and a Persistent Volume that connects to the new GCE disk (gce-pv.yaml).

Example 2. Finance History PV Object

  1. apiVersion: v1
  2. kind: PersistentVolume
  3. metadata:
  4. name: pv-finance-history
  5. spec:
  6. capacity:
  7. storage: 35Gi
  8. accessModes:
  9. - ReadWriteMany
  10. gcePersistentDisk:
  11. readOnly: false
  12. pdName: the-existing-PD-volume-name-that-contains-the-valuable-data (2)
  13. fsType: ext4
  14. storageClassName: finance-history (1)
1The StorageClass name, that must match exactly.
2The name of the GCE disk that already exists and contains the legacy data.

As a cluster-admin or storage-admin, create and view the PV.

  1. # oc create -f gce-pv.yaml
  2. persistentvolume "pv-finance-history" created
  3. # oc get pv
  4. NAME CAPACITY ACCESSMODES RECLAIMPOLICY STATUS CLAIM REASON AGE
  5. pv-finance-history 35Gi RWX Retain Available 2d

Notice you have a pv-finance-history Available and ready for consumption.

As a user, create a Persistent Volume Claim (PVC) as a YAML file and specify the correct StorageClass name:

Example 3. Claim for finance-history Object Definition

  1. apiVersion: v1
  2. kind: PersistentVolumeClaim
  3. metadata:
  4. name: pvc-finance-history
  5. spec:
  6. accessModes:
  7. - ReadWriteMany
  8. resources:
  9. requests:
  10. storage: 20Gi
  11. storageClassName: finance-history (1)
1The StorageClass name, that must match exactly or the claim will go unbound until it is deleted or another StorageClass is created that matches the name.

Create and view the PVC and PV to see if it is bound.

  1. # oc create -f pvc-finance-history.yaml
  2. persistentvolumeclaim "pvc-finance-history" created
  3. # oc get pvc
  4. NAME STATUS VOLUME CAPACITY ACCESSMODES AGE
  5. pvc-finance-history Bound pv-finance-history 35Gi RWX 9m
  6. # oc get pv (cluster/storage-admin)
  7. NAME CAPACITY ACCESSMODES RECLAIMPOLICY STATUS CLAIM REASON AGE
  8. pv-finance-history 35Gi RWX Retain Bound default/pvc-finance-history 5m

You can use StorageClasses in the same cluster for both legacy data (no dynamic provisioning) and with dynamic provisioning.