Skip to content

Expand a volume

As dynamic volume expansion is not activated, if one edits directly in the YAML object the size of the volume, an error like this will be returned:

(...)
# * spec: Forbidden: spec is immutable after creation except resources.requests for bound claims
(...)

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:
  name: two-volumes
spec:
  replicas: 1
  selector:
    app: two-volumes
  template:
    metadata:
      labels:
        app: two-volumes
    spec:
      containers:
      - image: cscfi/nginx-okd:plus
        name: two-volumes
        ports:
        - containerPort: 8081
          protocol: TCP
        volumeMounts:
        - mountPath: /new
          name: new-volume
        - mountPath: /old
          name: old-volume
      volumes:
      - name: new-volume
        persistentVolumeClaim:
          claimName: new-volume
      - name: old-volume
        persistentVolumeClaim:
          claimName: old-volume
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.