kubectl directpv init
The kubectl directpv init command formats selected drives with the XFS filesystem and mounts them for DirectPV to manage.
DirectPV uses initialized drives to provision PersistentVolumes in response to PersistentVolumeClaims with the directpv-min-io StorageClass.
Before running this command, use kubectl directpv discover to generate the drives.yaml configuration file.
Review the file and remove any drives you do not want to format.
For a complete workflow including discovery, initialization, and drive management, see Managing Drives.
drives.yaml file before running init.
Syntax
Parameters
INPUT_FILE
Required
The path to the YAML configuration file containing the drives to initialize.
This file is generated by the kubectl directpv discover command.
--dangerous
Required
Confirms that you understand this operation permanently erases all existing data on the selected drives. The command does not run without this flag.
--timeout
Optional
Set a timeout duration for the initialization 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
Initialize drives from the default configuration file
Initialize all drives listed in drives.yaml:
kubectl directpv init drives.yaml --dangerous
Initialize drives from a custom configuration file
Initialize drives from a file in a different location:
kubectl directpv init /tmp/production-drives.yaml --dangerous
Initialize with extended timeout
For large clusters, increase the timeout to allow all nodes to complete initialization:
kubectl directpv init drives.yaml --dangerous --timeout=10m
Behavior
Initialization process
When you run the init command, DirectPV performs the following operations on each selected drive:
- Formats the drive with the XFS filesystem
- Mounts the drive to
/var/lib/directpv/mnt/<UUID> - Registers the drive as available for PersistentVolume provisioning
Drive requirements
Drives must meet the following conditions to be initialized:
- Listed in the input configuration file.
- Available (no existing filesystem, partition table, or mount).
- Accessible by the DirectPV DaemonSet on the target node.
Use kubectl directpv discover --all to see why specific drives may be unavailable.
Output interpretation
The command displays a table showing the initialization results:
| Column | Description |
|---|---|
REQUESTID |
Unique identifier for the initialization request |
NODE |
The Kubernetes node where the drive is located |
DRIVE |
The device path (for example, /dev/sdb) |
MESSAGE |
Success or an error message explaining the failure |
Error handling
If initialization fails for a drive, the command continues processing remaining drives. Review the output table to identify which drives failed and why.
Common failure reasons:
- Drive is in use by another process.
- Drive has an existing filesystem that was not detected during discovery.
- Node communication timeout.
For troubleshooting, see kubectl directpv list-drives to check drive status.