kubectl directpv label drives

The kubectl directpv label drives command adds or removes custom labels on drives managed by DirectPV. Use labels to organize drives and control volume scheduling with the directpv-min-io StorageClass.

For information on using labels to schedule volumes to specific drives, see Volume Scheduling and Schedule Volumes by Label.

Syntax

Aliases

The following aliases have the same function:

  • kubectl directpv label drive
  • kubectl directpv label dr

Parameters

KEY=VALUE

Add or update a label on the selected drives. Specify multiple KEY=VALUE pairs separated by spaces to add multiple labels.

KEY-

Remove a label from the selected drives. Specify multiple KEY- arguments separated by spaces to remove multiple labels. You can only remove custom labels. You cannot remove the default DirectPV labels.

--all

Optional

Select all drives. When specified, DirectPV ignores other selection flags.

--nodes

Optional

Select drives on specific nodes. Supports ellipsis expansion notation.

Short form: -n

--drives

Optional

Select drives by name. Supports ellipsis expansion notation.

Short form: -d

--ids

Optional

Select drives by drive ID. Specify multiple IDs as a comma-separated list or by repeating the flag.

--labels

Optional

Select drives by existing labels. Supports comma-separated key=value pairs. When specifying multiple labels, drives must match all labels (AND logic).

--status

Optional

Select drives by 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 what changes would be made without applying them.

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

Add a label to all drives

Set a tier label with value hot on all drives:

kubectl directpv label drives tier=hot --all

Add multiple labels at once

Set multiple labels on all drives in a single command:

kubectl directpv label drives tier=hot environment=production --all

Add a label to drives on specific nodes

Set a type label on NVMe drives on node1:

kubectl directpv label drives type=fast --nodes=node1 --drives=nvme1n{1...3}

Add a label to drives by status

Label all drives in ready status:

kubectl directpv label drives environment=production --status=ready

Remove a label from all drives

Remove the tier label from all drives:

kubectl directpv label drives tier- --all

Preview changes with dry run

See what changes would be made without applying them:

kubectl directpv label drives tier=hot --all --dry-run

Behavior

Label format

Labels follow Kubernetes label syntax:

  • Keys and values must be 63 characters or fewer.
  • Keys and values must begin and end with alphanumeric characters.
  • Keys and values may contain dashes, underscores, and dots.

Default labels

DirectPV applies default labels to drives for internal use. These labels cannot be removed. Use kubectl directpv list-drives to view all labels on a drive.

Selection requirements

You must specify at least one selection flag (--all, --nodes, --drives, --ids, --labels, or --status) to identify which drives to label.

When you specify multiple selection flags, DirectPV selects only drives that match all criteria (AND logic). For example, --nodes=node1 --status=ready selects only drives on node1 that are also in ready status.