We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

Learn how to – How To Expand PVC in OpenShift with OCS Storage

Learn how to – How To Expand PVC in OpenShift with OCS Storage.

The OpenShift Container Platform uses the Kubernetes persistent volume (PV) framework to allow cluster administrators to provision persistent storage for cluster operations that require data persistence. As a developer you can use persistent volume claims (PVCs) to request PV resources without having specific knowledge of the underlying storage infrastructure.

In this short guide you’ll learn how to expand an existing PVC in OpenShift when using OpenShift Container Storage. Before you can expand persistent volumes, the StorageClass must have the allowVolumeExpansion field set to true.

Here is a list of Storage classes available in my OpenShift cluster.

$ oc get sc
NAME                                  PROVISIONER                             RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
localblock                            kubernetes.io/no-provisioner            Delete          WaitForFirstConsumer   false                  186d
localfile                             kubernetes.io/no-provisioner            Delete          WaitForFirstConsumer   false                  186d
ocs-storagecluster-ceph-rbd           openshift-storage.rbd.csi.ceph.com      Delete          Immediate              false                  169d
ocs-storagecluster-cephfs (default)   openshift-storage.cephfs.csi.ceph.com   Delete          Immediate              true                   169d
openshift-storage.noobaa.io           openshift-storage.noobaa.io/obc         Delete          Immediate              false                  169d
thin                                  kubernetes.io/vsphere-volume            Delete          Immediate              false                  169d
unused                                kubernetes.io/no-provisioner            Delete          WaitForFirstConsumer   false                  190d

I’ll change the default storage class which is ocs-storagecluster-cephfs. Let’s export the configuration to yaml file:

oc get sc ocs-storagecluster-cephfs -o yaml >ocs-storagecluster-cephfs.yml

I’ll modify the file to add allowVolumeExpansion field.

allowVolumeExpansion: true
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  annotations:
    storageclass.kubernetes.io/is-default-class: "true"
  name: ocs-storagecluster-cephfs
parameters:
  clusterID: openshift-storage
  csi.storage.k8s.io/node-stage-secret-name: rook-csi-cephfs-node
  csi.storage.k8s.io/node-stage-secret-namespace: openshift-storage
  csi.storage.k8s.io/provisioner-secret-name: rook-csi-cephfs-provisioner
  csi.storage.k8s.io/provisioner-secret-namespace: openshift-storage
  fsName: ocs-storagecluster-cephfilesystem
provisioner: openshift-storage.cephfs.csi.ceph.com
reclaimPolicy: Delete
volumeBindingMode: Immediate
allowVolumeExpansion: true # Added field

Delete current configured storageclass since a SC is immutable resource.

$ oc delete sc ocs-storagecluster-cephfs
storageclass.storage.k8s.io "ocs-storagecluster-cephfs" deleted

Apply modified storage class configuration by running the following command:

$ oc apply -f ocs-storagecluster-cephfs.yml 
storageclass.storage.k8s.io/ocs-storagecluster-cephfs created

List storage classes to confirm it was indeed created.

$ oc get sc
NAME                                  PROVISIONER                             RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
localblock                            kubernetes.io/no-provisioner            Delete          WaitForFirstConsumer   false                  186d
localfile                             kubernetes.io/no-provisioner            Delete          WaitForFirstConsumer   false                  186d
ocs-storagecluster-ceph-rbd           openshift-storage.rbd.csi.ceph.com      Delete          Immediate              false                  169d
ocs-storagecluster-cephfs (default)   openshift-storage.cephfs.csi.ceph.com   Delete          Immediate              true                   5m20s
openshift-storage.noobaa.io           openshift-storage.noobaa.io/obc         Delete          Immediate              false                  169d
thin                                  kubernetes.io/vsphere-volume            Delete          Immediate              false                  169d
unused                                kubernetes.io/no-provisioner            Delete          WaitForFirstConsumer   false                  190d

Output yalm and confirm the new setting was applied.

$ oc get sc ocs-storagecluster-cephfs -o yaml
allowVolumeExpansion: true
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"allowVolumeExpansion":true,"apiVersion":"storage.k8s.io/v1","kind":"StorageClass","metadata":{"annotations":{"storageclass.kubernetes.io/is-default-class":"true"},"name":"ocs-storagecluster-cephfs"},"parameters":{"clusterID":"openshift-storage","csi.storage.k8s.io/node-stage-secret-name":"rook-csi-cephfs-node","csi.storage.k8s.io/node-stage-secret-namespace":"openshift-storage","csi.storage.k8s.io/provisioner-secret-name":"rook-csi-cephfs-provisioner","csi.storage.k8s.io/provisioner-secret-namespace":"openshift-storage","fsName":"ocs-storagecluster-cephfilesystem"},"provisioner":"openshift-storage.cephfs.csi.ceph.com","reclaimPolicy":"Delete","volumeBindingMode":"Immediate"}
    storageclass.kubernetes.io/is-default-class: "true"
  creationTimestamp: "2020-10-31T13:33:56Z"
  name: ocs-storagecluster-cephfs
  resourceVersion: "242503097"
  selfLink: /apis/storage.k8s.io/v1/storageclasses/ocs-storagecluster-cephfs
  uid: 5aa95d3b-c39c-438d-85af-5c8550d6ed5b
parameters:
  clusterID: openshift-storage
  csi.storage.k8s.io/node-stage-secret-name: rook-csi-cephfs-node
  csi.storage.k8s.io/node-stage-secret-namespace: openshift-storage
  csi.storage.k8s.io/provisioner-secret-name: rook-csi-cephfs-provisioner
  csi.storage.k8s.io/provisioner-secret-namespace: openshift-storage
  fsName: ocs-storagecluster-cephfilesystem
provisioner: openshift-storage.cephfs.csi.ceph.com
reclaimPolicy: Delete
volumeBindingMode: Immediate

How To Expand a PVC in OpenShift

List available PVCs in the namespace.

$ oc get pvc
NAME                                     STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS                AGE
data-harbor-harbor-redis-0               Bound    pvc-e516b793-60c5-431d-955f-b1d57bdb556b   1Gi        RWO            ocs-storagecluster-cephfs   169d
database-data-harbor-harbor-database-0   Bound    pvc-00a53065-9790-4291-8f00-288359c00f6c   2Gi        RWO            ocs-storagecluster-cephfs   169d
harbor-harbor-chartmuseum                Bound    pvc-405c68de-eecd-4db1-9ca1-5ca97eeab37c   5Gi        RWO            ocs-storagecluster-cephfs   169d
harbor-harbor-jobservice                 Bound    pvc-e52f231e-0023-41ad-9aff-98ac53cecb44   2Gi        RWO            ocs-storagecluster-cephfs   169d
harbor-harbor-registry                   Bound    pvc-77e159d4-4059-47dd-9c61-16a6e8b37a14   100Gi      RWX            ocs-storagecluster-cephfs   39d

Edit PVC and change capacity

$ oc edit pvc data-harbor-harbor-redis-0 
...
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi

Delete pod with claim.

$ oc delete pods harbor-harbor-redis-0
pod "harbor-harbor-redis-0" deleted

Recreate the deployment that was claiming the storage and it should utilize the new capacity.

Expanding PVC on OpenShift Web Console

You can also expand a PVC from the web console.

Click on “Expand PVC” and set the desired PVC capacity.

More articles on OpenShift.

How To Deploy Ubuntu Pod in Kubernetes|OpenShift

Configure Static IPv4 Address in OpenShift 4.x CoreOS Servers

How To List and Approve Pending CSR in OpenShift 4.x

Cart

Your Cart is Empty

Back To Shop