kubectl directpv label volumes

The kubectl directpv label volumes command adds or removes custom labels on volumes managed by DirectPV. Use labels to organize volumes and identify them for operational purposes.

For step-by-step procedures on volume operations, see Managing Volumes. For information on labeling drives for volume scheduling, see kubectl directpv label drives.

Syntax

Aliases

The following aliases have the same function:

  • kubectl directpv label volume
  • kubectl directpv label vol

Parameters

KEY=VALUE

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

KEY-

Remove a label from the selected volumes. 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 volumes. When specified, DirectPV ignores other selection flags.

--nodes

Optional

Select volumes on specific nodes. Supports ellipsis expansion notation.

Short form: -n

--drives

Optional

Select volumes on specific drives by name. Supports ellipsis expansion notation.

Short form: -d

--drive-id

Optional

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

--ids

Optional

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

--pod-names

Optional

Select volumes by pod name. Specify multiple names as a comma-separated list or by repeating the flag. Supports ellipsis expansion notation.

--pod-namespaces

Optional

Select volumes by pod namespace. Specify multiple namespaces as a comma-separated list or by repeating the flag. Supports ellipsis expansion notation.

--status

Optional

Select volumes by status. Specify multiple statuses as a comma-separated list or by repeating the flag.

Valid values: pending, ready

--labels

Optional

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

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 volumes

Set a tier label with value hot on all volumes:

kubectl directpv label volumes tier=hot --all

Add multiple labels at once

Set multiple labels on all volumes in a single command:

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

Add a label to volumes on specific drives

Set a type label on volumes allocated to NVMe drives on node1:

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

Add a label to volumes by pod name

Label volumes used by specific pods:

kubectl directpv label volumes app=minio --pod-names=minio-{0...3}

Add a label to volumes by status

Label all volumes in ready status:

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

Add a label to volumes by drive ID

Label volumes on specific drives using their drive IDs:

kubectl directpv label volumes tier=hot --drive-id=3b562992-f752-4a41-8be4-4e688ae8cd4c,a1b2c3d4-e5f6-7890-abcd-ef1234567890

Remove a label from all volumes

Remove the tier label from all volumes:

kubectl directpv label volumes tier- --all

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 volumes for internal use. You cannot remove these labels cannot. Use kubectl directpv list volumes to view all labels on a volume.

Selection requirements

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

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