kubectl directpv discover

The kubectl directpv discover command scans Kubernetes nodes for available block devices and generates a YAML configuration file listing drives that DirectPV can manage.

After running discovery, review the generated file and remove any drives you do not want DirectPV to format. Then use kubectl directpv init to initialize the selected drives.

For a complete workflow including discovery, initialization, and drive management, see Managing Drives.

Syntax

Parameters

--nodes

Optional

Discover drives only from specified nodes. Supports ellipsis expansion notation.

Short form: -n

--drives

Optional

Discover only drives matching the specified names. Supports ellipsis expansion notation.

Short form: -d

--all

Optional

Include all devices in the output, including those that DirectPV cannot format. Without this flag, the command only displays drives available for initialization.

Use this flag to see why certain drives are unavailable (for example, drives with existing filesystems or partitions).

--output-file

Optional

Specify the path and filename for the generated configuration file.

Default: drives.yaml

--timeout

Optional

Set a timeout duration for the discovery process.

Default: 2m0s

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

Discover all drives in the cluster

Scan all nodes for available block devices:

kubectl directpv discover

Discover drives on specific nodes

Scan only node1 for available drives:

kubectl directpv discover --nodes=node1

Scan a range of nodes using ellipsis expansion:

kubectl directpv discover --nodes=node{1...4}

Discover specific drive types

Find all nvme1n1 drives across the cluster:

kubectl directpv discover --drives=nvme1n1

Find a range of SATA drives:

kubectl directpv discover --drives=sd{a...f}

Discover specific drives on specific nodes

Combine node and drive filters:

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

Include unavailable drives in output

Display all drives, including those that cannot be formatted:

kubectl directpv discover --all

This shows drives with existing filesystems, partitions, or other conditions that prevent DirectPV from using them.

Save configuration to a custom file

Write the discovery results to a specific file:

kubectl directpv discover --output-file=/tmp/production-drives.yaml

Behavior

Output file generation

The discover command generates a YAML configuration file (default: drives.yaml) containing all available drives. This file serves as input for the kubectl directpv init command.

Review before initializing
Always review the generated YAML file before running init. Remove any drives that should not be formatted, as initialization erases all data on selected drives.

Drive availability

A drive is considered available for DirectPV if it meets these conditions:

  • No existing filesystem.
  • No partition table.
  • Not currently mounted.
  • Not in use by another storage system.

Use the --all flag to see drives that fail these conditions and understand why they are unavailable.

For information about installing DirectPV, see the installation guide.

Ellipsis expansion

Both --nodes and --drives flags support ellipsis expansion notation for specifying ranges:

Pattern Expands to
node{1...4} node1, node2, node3, node4
sd{a...d} sda, sdb, sdc, sdd
nvme{0...2}n1 nvme0n1, nvme1n1, nvme2n1

Timeout handling

The discovery process has a default timeout of 2 minutes. For large clusters with many nodes, increase the timeout using the --timeout flag to ensure all nodes are scanned.