Dynamic Storage - Almax84/consulting-wiki GitHub Wiki

There are two ways of provisioning storage for the cluster: static and dynamic. Static provisioning requires the cluster administrator to create persistent volumes manually. Dynamic provisioning uses storage classes to create the persistent volumes on demand.

The OpenShift Container Platform uses storage classes to allow administrators to provide persistent storage. Storage classes are a way to describe types of storage for the cluster and provision dynamic storage on demand.

A persistent volume claim (PVC) belongs to a specific project. To create a PVC, you must specify the access mode and size, among other options. Once created, a PVC cannot be shared between projects.

Persistent volume claims request persistent volume resources. To be eligible, a PV must not be bound to another PVC.

Get the available storage class: oc get storageclass

The command creates a persistent volume claim resource and adds it to the application as a volume within the pod. To add a volume to an application, use the oc set volumes command:

[user@host ~]$ oc set volumes deployment/example-application
--add --name example-storage --type pvc --claim-class nfs-storage
--claim-mode rwo --claim-size 15Gi --mount-path /var/lib/example-app
--claim-name example-storage

API Object:

apiVersion: v1  
kind: PersistentVolumeClaim    
metadata:  
  name: example-pv-claim  
  labels:  
    app: example-application  
spec:  
  accessModes:  
    - ReadWriteOnce  
  resources:  
    requests:  
      storage: 15Gi  

Access Mode CLI Abbreviation Description

ReadWriteMany RWX Kubernetes can mount the volume as read-write on many nodes.
ReadOnlyMany ROX Kubernetes can mount the volume as read-only on many nodes.
ReadWriteOnce RWO Kubernetes can mount the volume as read-write on only a single node.

To add the PVC to the APP:

spec:  
   volumes:  
     - name: example-pv-storage  
       persistentVolumeClaim:  
         claimName: example-pv-claim  
   containers:  
   - name: example-application  
     image: registry.redhat.io/rhel8/example-app  
     ports:  
     - containerPort: 1234  
     volumeMounts:  
       - mountPath: "/var/lib/example-app"  
         name: example-pv-storage  

Deletign PVC
oc delete pvc/example-pvc-storage

EXAMPLE

oc set volumes deployment/postgresql-persistent
--add --name postgresql-storage --type pvc --claim-class nfs-storage
--claim-mode rwo --claim-size 10Gi --mount-path /var/lib/pgsql
--claim-name postgresql-storage

Show the newly created PVC
oc get pvc

Show the PV
oc get pv -o custom-columns=NAME:.metadata.name,CLAIM:.spec.claimRef.name

see: https://role.rhu.redhat.com/rol-rhu/app/courses/do280-4.6/pages/ch02s06