Skip to content

Expand a volume

Warning-label

This version of Rahti is deprecated. The projects need to be migrated from Rahti Beta platform to the new Rahti production platform by June 2024. Please consult the migration guide for more information.

Non dynamically

When dynamic volume expansion is not activated, the command line will give an error like:

error: persistentvolumeclaims "postgresql" could not be patched: persistentvolumeclaims "postgresql" is forbidden: only dynamically provisioned pvc can be resized and the storageclass that provisions the pvc must support resize

Then a more artisanal procedure must be followed:

  • Create a new volume with the desired size

Create a new volume

  • Scale down the deployment that mounts the volume that is being resized.

Scale down

  • Mount the old and new volume in another Pod. The best option is to create a new deployment, create a file called two-volumes.yaml and replace the names of both volumes:
apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
  labels:
    app: two-volumes
  name: two-volumes
spec:
  replicas: 1
  selector:
    app: two-volumes
    deploymentconfig: two-volumes
  strategy:
    activeDeadlineSeconds: 21600
    type: Rolling
  template:
    metadata:
      labels:
        app: two-volumes
        deploymentconfig: two-volumes
    spec:
        containers:
        - image: cscfi/nginx-okd:plus
          imagePullPolicy: IfNotPresent
          name: two-volumes
          resources: {}
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          volumeMounts:
            - mountPath: /old
              name: old
            - mountPath: /new
              name: new
        dnsPolicy: ClusterFirst
        restartPolicy: Always
        schedulerName: default-scheduler
        securityContext: {}
        terminationGracePeriodSeconds: 30
        volumes:
          - name: old
            persistentVolumeClaim:
              claimName: <name of old volume>
          - name: new
            persistentVolumeClaim:
              claimName: <name of new volume>
  test: false
  triggers: {}
status: {}
oc create -f two-volumes.yaml
  • Sync the data
oc rsh dc/two-volumes rsync -vrlpD /old/ /new/
  • Delete that new Pod
oc delete dc/two-volumes
  • Exchange volumes in the deployment that was mounting the volume, it is at template > spec > volumes under claimName.
oc edit deploy/<name of deployment>
  • Finally scale up the deployment.

In order to check the procedure worked, you may enter in a Pod that is mounting the volume and check the new size.


Last update: October 31, 2023