Skip to content

Latest commit

 

History

History
174 lines (154 loc) · 6.45 KB

volume-management.md

File metadata and controls

174 lines (154 loc) · 6.45 KB

Volume management

Prerequisites

Add volume

Refer to the volume provisioning guide.

List volume

To get information of volumes from DirectPV, run the list volumes command. Below is an example:

$ kubectl directpv list drives
┌────────┬──────┬──────┬─────────┬─────────┬─────────┬────────┐
│ NODE   │ NAME │ MAKE │ SIZE    │ FREE    │ VOLUMES │ STATUS │
├────────┼──────┼──────┼─────────┼─────────┼─────────┼────────┤
│ master │ vdb  │ -    │ 512 MiB │ 506 MiB │ -       │ Ready  │
│ node1  │ vdb  │ -    │ 512 MiB │ 506 MiB │ -       │ Ready  │
└────────┴──────┴──────┴─────────┴─────────┴─────────┴────────┘

Refer to the list volumes command for more information.

Expand volume

DirectPV supports online volume expansion which does not require restart of pods using those volumes. This is automatically done after setting expanded size to Persistent Volume Claim. Below is an example:

# Get 'minio-data-1-minio-0' Persistent volume claim.
$ kubectl get pvc minio-data-1-minio-0 -o yaml > minio-data-1-minio-0.yaml

$ cat minio-data-1-minio-0.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  annotations:
    pv.kubernetes.io/bind-completed: "yes"
    pv.kubernetes.io/bound-by-controller: "yes"
    volume.beta.kubernetes.io/storage-provisioner: directpv-min-io
    volume.kubernetes.io/selected-node: master
    volume.kubernetes.io/storage-provisioner: directpv-min-io
  creationTimestamp: "2023-06-08T04:46:02Z"
  finalizers:
  - kubernetes.io/pvc-protection
  labels:
    app: minio
  name: minio-data-1-minio-0
  namespace: default
  resourceVersion: "76360"
  uid: d7fad69a-d267-43c0-9baf-19fd5f65bdb5
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 16Mi
  storageClassName: directpv-min-io
  volumeMode: Filesystem
  volumeName: pvc-d7fad69a-d267-43c0-9baf-19fd5f65bdb5
status:
  accessModes:
  - ReadWriteOnce
  capacity:
    storage: 16Mi
  phase: Bound

# Edit 'minio-data-1-minio-0' PVC to increase the size from 16MiB to 64MiB.
$ cat minio-data-1-minio-0.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  annotations:
    pv.kubernetes.io/bind-completed: "yes"
    pv.kubernetes.io/bound-by-controller: "yes"
    volume.beta.kubernetes.io/storage-provisioner: directpv-min-io
    volume.kubernetes.io/selected-node: master
    volume.kubernetes.io/storage-provisioner: directpv-min-io
  creationTimestamp: "2023-06-08T04:46:02Z"
  finalizers:
  - kubernetes.io/pvc-protection
  labels:
    app: minio
  name: minio-data-1-minio-0
  namespace: default
  resourceVersion: "76360"
  uid: d7fad69a-d267-43c0-9baf-19fd5f65bdb5
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 64Mi   # <--- increase size here
  storageClassName: directpv-min-io
  volumeMode: Filesystem
  volumeName: pvc-d7fad69a-d267-43c0-9baf-19fd5f65bdb5
status:
  accessModes:
  - ReadWriteOnce
  capacity:
    storage: 16Mi
  phase: Bound

# Apply changes
$ kubectl apply -f minio-data-1-minio-0.yaml

# After successful expansion, you will see updated YAML
$ kubectl get pvc minio-data-1-minio-0 -o yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  annotations:
    pv.kubernetes.io/bind-completed: "yes"
    pv.kubernetes.io/bound-by-controller: "yes"
    volume.beta.kubernetes.io/storage-provisioner: directpv-min-io
    volume.kubernetes.io/selected-node: master
    volume.kubernetes.io/storage-provisioner: directpv-min-io
  creationTimestamp: "2023-06-08T04:46:02Z"
  finalizers:
  - kubernetes.io/pvc-protection
  labels:
    app: minio
  name: minio-data-1-minio-0
  namespace: default
  resourceVersion: "76651"
  uid: d7fad69a-d267-43c0-9baf-19fd5f65bdb5
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 64Mi
  storageClassName: directpv-min-io
  volumeMode: Filesystem
  volumeName: pvc-d7fad69a-d267-43c0-9baf-19fd5f65bdb5
status:
  accessModes:
  - ReadWriteOnce
  capacity:
    storage: 64Mi # <--- increased size here
  phase: Bound

Delete volume

CAUTION: THIS IS DANGEROUS OPERATION WHICH LEADS TO DATA LOSS

Volume can be deleted only if it is in Ready state (that is, no pod is using it). Run the kubectl delete pvc command which triggers DirectPV volume deletion. As removing a volume leads to data loss, double check what volume you are deleting. Below is an example:

# Delete `sleep-pvc` volume
kubectl delete pvc sleep-pvc

Clean stale volumes

When Pods and/or Persistent Volume Claims are deleted forcefully, associated DirectPV volumes might be left undeleted and they becomes stale. These stale volumes are removed by running clean command. Below is an example:

$ kubectl directpv clean --all

Refer clean command for more information.

Suspend volumes

CAUTION: THIS IS DANGEROUS OPERATION WHICH LEADS TO DATA LOSS

By Kubernetes design, StatefulSet workload is active only if all of its pods are in running state. Any faulty volume(s) will prevent the statefulset from starting up. DirectPV provides a workaround to suspend failed volumes by mounting them on empty /var/lib/directpv/tmp directory with read-only access. This can be done by executing the suspend volumes command. Below is an example:

> kubectl directpv suspend volumes --nodes node-1 --drives dm-3

Suspended volumes can be resumed once they are fixed. Upon resuming, the corresponding volumes will resume using the respective allocated drives. This can be done by using the resume volumes command. Below is an example:

> kubectl directpv resume volumes --nodes node-1 --drives dm-3