kubectl directpv clean
The kubectl directpv clean command removes volumes that are in released or deleted status.
Use this command to reclaim storage space from volumes that are no longer in use by Kubernetes workloads.
Syntax
Parameters
VOLUME
Optional
The name of one or more volumes to clean.
Specify multiple volume names separated by spaces.
Use kubectl directpv list volumes to find volume names.
--all
Optional
Clean all stale volumes across all nodes. When specified, DirectPV ignores other selection flags.
--nodes
Optional
Clean volumes on specific nodes. Specify multiple nodes as a comma-separated list or by repeating the flag. Supports ellipsis expansion notation.
Short form: -n
--drives
Optional
Clean volumes on drives with specific names. Specify multiple drives as a comma-separated list or by repeating the flag. Supports ellipsis expansion notation.
Short form: -d
--drive-id
Optional
Clean volumes on drives with specific IDs. Specify multiple drive IDs as a comma-separated list or by repeating the flag.
--pod-names
Optional
Clean volumes associated with specific pod names. Specify multiple pod names as a comma-separated list or by repeating the flag. Supports ellipsis expansion notation.
--pod-namespaces
Optional
Clean volumes in specific pod namespaces. Specify multiple namespaces as a comma-separated list or by repeating the flag. Supports ellipsis expansion notation.
--dry-run
Optional
Display what volumes would be cleaned without making changes.
Global flags
This command supports the following global flags:
| Flag | Description |
|---|---|
--kubeconfig |
Path to the kubeconfig file to use for CLI requests. |
--quiet |
Suppress printing error messages. |
Examples
Clean all stale volumes
Remove all volumes in released or deleted status:
kubectl directpv clean --all
Clean a specific volume
Remove a volume by its name:
kubectl directpv clean pvc-6355041d-f9c6-4bd6-9335-f2bccbe73929
Clean volumes on a specific drive
Remove stale volumes on a drive by name:
kubectl directpv clean --drives=nvme1n1
Clean volumes on a drive by ID
Remove stale volumes on a specific drive:
kubectl directpv clean --drive-id=78e6486e-22d2-4c93-99d0-00f4e3a8411f
Clean volumes on a node
Remove stale volumes on a specific node:
kubectl directpv clean --nodes=node1
Clean volumes by pod name
Remove stale volumes from specific pods using ellipsis expansion:
kubectl directpv clean --pod-names=minio-{1...3}
Clean volumes by namespace
Remove stale volumes from specific namespaces:
kubectl directpv clean --pod-namespaces=tenant-{1...3}
Preview clean operation
Check which volumes would be cleaned without making changes:
kubectl directpv clean --all --dry-run
Behavior
What volumes are cleaned?
The clean command only removes volumes that are in one of these states:
- Released: The PersistentVolumeClaim was deleted, but the volume has not been reclaimed.
- Deleted: The volume is marked for deletion.
Volumes that are actively bound to pods are not affected.
Selection requirements
This command requires at least one selection method. The command returns an error if no volumes are selected.
When to use clean
Run the clean command periodically to:
- Reclaim storage space from deleted workloads.
- Remove orphaned volumes after application uninstallation.
- Clean up after failed deployments.
Verify volumes before cleaning
Before cleaning, list volumes to see their status:
kubectl directpv list volumes --all
Volumes with Released or Deleted status are candidates for cleaning.