kubectl directpv cordon

The kubectl directpv cordon command prevents DirectPV from scheduling new volumes on selected drives. Existing volumes on cordoned drives remain accessible.

Cordoning is useful when you want to:

  • Prepare drives for maintenance without disrupting existing workloads.
  • Prevent volume scheduling on drives with errors.
  • Phase out drives before removal.

To allow new volumes on cordoned drives again, use kubectl directpv uncordon.

Syntax

Parameters

DRIVE_ID

Optional

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

--all

Optional

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

--nodes

Optional

Cordon 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

Cordon drives by name. Specify multiple drives as a comma-separated list or by repeating the flag. Supports ellipsis expansion notation.

Short form: -d

--status

Optional

Cordon drives with a specific status. Specify multiple statuses as a comma-separated list or by repeating the flag. Valid values: error, lost, moving, ready, removed.

--dry-run

Optional

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

Cordon all drives in the cluster

Prevent volume scheduling on all drives:

kubectl directpv cordon --all

Cordon drives on multiple nodes using ellipsis notation

Use ellipsis expansion to cordon drives across a range of nodes:

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

Cordon drives with errors

Prevent scheduling on all drives that have error status:

kubectl directpv cordon --status=error

Preview cordon operation for drives on a node

Check the drives to cordoned, without making changes:

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

Behavior

How cordoning works

Cordoning blocks a drive from receiving new volumes. When you cordon a drive:

  1. DirectPV marks the drive as cordoned.
  2. New volume scheduling requests skip the cordoned drive.
  3. Existing volumes on the drive remain accessible and functional.
  4. The drive status shows Cordoned when listed.

Selection requirements

This command requires at least one selection method. The command returns an error if no drives are selected.

Cordoning and volume scheduling

DirectPV uses the directpv-min-io StorageClass with WaitForFirstConsumer volume binding mode. When a pod requests a PersistentVolume:

  1. DirectPV evaluates available drives based on capacity and topology.
  2. Cordoned drives are excluded from consideration.
  3. DirectPV selects from remaining eligible drives.

For more details on volume scheduling, see Volume Scheduling.

Verify cordoned drives

After cordoning, verify the drive status:

kubectl directpv list drives --all

Cordoned drives show Cordoned in the status column.

Common use cases

Planned maintenance

Before taking a node offline for maintenance:

  1. Cordon the drives on that node.
  2. Perform maintenance tasks.
  3. Uncordon the drives when maintenance is complete.

Drive replacement

When replacing a drive:

  1. Cordon the drive to prevent new volumes.
  2. Migrate or delete existing volumes.
  3. Remove and replace the physical drive.
  4. Initialize the new drive with kubectl directpv init.

Isolating problematic drives

If a drive shows errors:

  1. Cordon the drive immediately.
  2. Investigate the issue.
  3. Suspend the drive if repair is needed using kubectl directpv suspend drives.