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
Discover all available drives across the cluster:
kubectl directpv discoverOutput:
┌────────────────┬───────┬──────────┬──────────┬────────────┬──────┬───────────┬─────────────┐
│ ID │ NODE │ DRIVE │ SIZE │ FILESYSTEM │ MAKE │ AVAILABLE │ DESCRIPTION │
├────────────────┼───────┼──────────┼──────────┼────────────┼──────┼───────────┼─────────────┤
│ a1b2c3d4e5f6...│ node1 │ /dev/sdb │ 100 GiB │ - │ - │ Yes │ - │
│ f6e5d4c3b2a1...│ node1 │ /dev/sdc │ 100 GiB │ - │ - │ Yes │ - │
│ 1a2b3c4d5e6f...│ node2 │ /dev/sdb │ 100 GiB │ - │ - │ Yes │ - │
└────────────────┴───────┴──────────┴──────────┴────────────┴──────┴───────────┴─────────────┘
Generated 'drives.yaml' successfully.kubectl directpv discover [--all] \
[-d|--drives "string"] \
[-n|--nodes "string"] \
[--output-file "string"] \
[--timeout "duration"]- Brackets
[]indicate optional parameters.
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 discoverDiscover drives on specific nodes
Scan only node1 for available drives:
kubectl directpv discover --nodes=node1Scan 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=nvme1n1Find 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 --allThis 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.yamlBehavior
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.