kubectl directpv remove

The kubectl directpv remove command removes unused drives from DirectPV management. Use this command to decommission drives that no longer have active volumes.

Unused drives only
This command only removes drives that have no active volumes. Drives with volumes are not removed. Use kubectl directpv list drives to verify a drive has no volumes before removal.

Syntax

Parameters

DRIVE

Optional

The drive ID of one or more drives to remove. Specify multiple drive IDs separated by spaces. Use kubectl directpv list drives to find drive IDs.

--all

Optional

Remove all unused drives across all nodes. When specified, DirectPV ignores other selection flags.

--nodes

Optional

Remove drives 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

Remove drives with specific names. Specify multiple drives as a comma-separated list or by repeating the flag. Supports ellipsis expansion notation.

Short form: -d

--status

Optional

Remove drives with a specific status. Specify multiple statuses as a comma-separated list or by repeating the flag.

Valid statuses:

  • error - Drives with filesystem or hardware errors
  • lost - Drives that are no longer detected
  • moving - Drives with volumes being moved
  • ready - Drives available for use
  • removed - Drives already marked for removal

--dry-run

Optional

Display drives to remove, 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

Remove unused drives from a node

Remove all unused drives from a specific node:

kubectl directpv remove --nodes=node1

Remove a specific drive by name

Remove a drive by its name from all nodes:

kubectl directpv remove --drives=nvme1n1

Remove drives from multiple nodes

Remove specific drives from multiple nodes using ellipsis expansion:

kubectl directpv remove --nodes=node{1...4} --drives=sd{a...f}

Remove all unused drives

Remove all unused drives across the entire cluster:

kubectl directpv remove --all

Remove drives by status

Remove all drives in error status:

kubectl directpv remove --status=error

Preview removal

Check which drives would be removed without making changes:

kubectl directpv remove --nodes=node1 --dry-run

Behavior

What the remove command does

The remove command:

  1. Identifies drives matching the selection criteria.
  2. Verifies each drive has no active volumes.
  3. Removes the drive from DirectPV management.
  4. The physical drive remains on the node but is no longer managed by DirectPV.

Requirements

  • Drives must have no active volumes to be removed.
  • You must specify at least one selection method.
  • The command returns an error if no drives match the criteria.

After removal

Once removed, a drive:

  • Is no longer managed by DirectPV.
  • Cannot receive new volume requests.
  • Remains physically attached to the node.
  • Can be re-added using kubectl directpv init.

Typical removal workflow

When decommissioning a drive:

  1. Cordon the drive to prevent new volumes:

    kubectl directpv cordon --drives=sda --nodes=node1
    
  2. Migrate or delete existing volumes from the drive.

  3. Verify the drive has no volumes:

    kubectl directpv list drives --nodes=node1 --drives=sda
    
  4. Remove the drive from DirectPV:

    kubectl directpv remove --drives=sda --nodes=node1