The module lifecycle stage: Generally available version
The module has requirements for installation
Module functionality is guaranteed only when using stock kernels provided with supported distributions.
Module functionality when using other kernels or distributions is possible but not guaranteed.
The controller works with two types of resources:
Working with BlockDevice resources
Creating a BlockDevice resource
The controller regularly scans devices on the node. If a device meets the controller requirements, a BlockDevice resource with a unique name is created, containing complete information about the device.
Controller requirements for devices
For the controller to create a BlockDevice resource for a device, it must meet the following requirements:
- The device must not be a DRBD device.
- The device must not be a pseudo-device (loop device).
- The device must not be a Logical Volume.
- The device must not be a block volume that kubelet has published to a workload on this node (a
volumeMode: BlockPersistentVolume attached to a pod, e.g. a virtual machine’s disk), nor a partition of one or a device stacked on one: whatever is written inside such a device belongs to the volume’s consumer. The agent’s LVM commands do not read these devices either. - The file system must be absent or of type
LVM2_MEMBER. - No other device may be built on the device: no partitions and no devices stacked on it (in the
lsblkoutput, the device has no children). An LVM Physical Volume is the exception: its Logical Volumes do not count. A disk with partitions therefore gets no BlockDevice resource of its own; each of its partitions is checked against these requirements as a separate device (see Creating a partition on a block device). - The block device size must exceed 1 GB.
- If the device is a virtual disk, it must have a serial number (see the FAQ for how to set it in different virtualization systems). A partition does not need a serial number if it has a PARTUUID.
The system disk
The controller has no separate rule for the disk the OS is installed on: it is checked against the same requirements as any other device. With a usual layout, therefore, neither the disk nor its partitions get a BlockDevice resource:
- The disk has partitions, so it gets no BlockDevice resource of its own.
- Partitions with a file system or another signature (the root,
/boot, the EFI partition, the swap partition) fail the file system requirement, and service partitions smaller than 1 GB fail the size requirement. - If the root is on LVM, its Logical Volumes are filtered out as Logical Volumes, and the Physical Volume (a partition or the whole disk) because its Volume Group is not managed by the module: the controller creates no BlockDevice resource for a Physical Volume of a Volume Group without the LVM tag
storage.deckhouse.io/enabled=true.
If the Volume Group with the root is handed over to the module with this tag, its Physical Volumes get BlockDevice resources, but they are not consumable, with the reason HasFilesystem: the devices are already taken by the Volume Group. A mounted device whose file system lsblk does not see (for example, its signature is missing from the udev database) also gets a BlockDevice resource, but it is not consumable, with the reason Mounted.
For how to give the module the free space on the system disk, see the FAQ.
Creating a partition on a block device
For the controller, a partition is a device of its own. After a partition is created on a block device, the controller creates a BlockDevice resource for the partition if the partition meets the requirements above, and stops creating one for the disk. If the disk already had a BlockDevice resource in the Consumable status, the controller deletes that resource.
A partition table without any partitions in it does not hide the disk: the disk still gets a BlockDevice resource, but it is not consumable, with the reason HasPartitionTable (see the FAQ).
Example of creating a partition on a block device:
fdisk /dev/sdbThe controller uses information from the created resource when working with LVMVolumeGroup resources.
Updating a BlockDevice resource
The controller automatically updates information in the resource when the state of the corresponding block device on the node changes.
Deleting a BlockDevice resource
The controller will automatically delete the resource if the corresponding block device becomes unavailable. Deletion will only occur in the following cases:
- If the resource was in Consumable status.
- If the block device belongs to a Volume Group that does not have the LVM tag
storage.deckhouse.io/enabled=true(this Volume Group is not managed by the module controller).
The controller performs all listed operations automatically without user intervention.
If the resource is manually deleted, it will be recreated by the controller.
Working with LVMVolumeGroup resources
BlockDevice resources are required to create and update LVMVolumeGroup resources. Currently, only local Volume Groups are supported.
LVMVolumeGroup resources are designed to interact with LVM Volume Groups on nodes and display current information about their state.
Using one LVM Volume Group with both SDS storage modules
If the same LVM Volume Group must be used with sds-replicated-volume and sds-local-volume at the same time, create several thin pools in that volume group and bind them separately: reference one thin pool in ReplicatedStoragePool and another in LocalStorageClass, using the thinPools entries declared in the LVMVolumeGroup resource.
Creating an LVMVolumeGroup resource
An LVMVolumeGroup resource can be created in three ways described below.
Automatic creation
The controller automatically scans LVM Volume Groups on nodes. If an LVM Volume Group has the LVM tag storage.deckhouse.io/enabled=true and the corresponding Kubernetes resource LVMVolumeGroup is missing, the controller creates it automatically.
In this case, the controller automatically fills all fields in the spec section of the resource, except thinPools. To manage an existing thin pool on the node, you need to manually add information about it to the spec section of the resource.
Creation by a user
The user manually creates the resource by filling in the metadata.name and spec fields, specifying the desired state of the new Volume Group.
The specified configuration is validated. After successful validation, the controller creates the LVM Volume Group on the node according to the configuration. Then the controller updates the LVMVolumeGroup resource with current information about the state of the created LVM Volume Group.
Manual Volume Group creation on the node
The user manually creates a Volume Group on the node using standard LVM commands.
After creating the Volume Group, the user adds the LVM tag storage.deckhouse.io/enabled=true to transfer control to the controller.
The controller automatically discovers the Volume Group with this tag and creates the corresponding LVMVolumeGroup resource.
Examples of creating LVMVolumeGroup resources
The examples below show various configuration options using different selectors and with or without thin pool.
Examples without thin pool:
Creating an LVM Volume Group with selection of specific devices by BlockDevice resource names (using matchExpressions):
apiVersion: storage.deckhouse.io/v1alpha1
kind: LVMVolumeGroup
metadata:
name: "vg-0-on-node-0"
spec:
type: Local
local:
nodeName: "node-0"
blockDeviceSelector:
matchExpressions:
- key: kubernetes.io/metadata.name
operator: In
values:
- dev-07ad52cef2348996b72db262011f1b5f896bb68f
- dev-e90e8915902bd6c371e59f89254c0fd644126da7
actualVGNameOnTheNode: "vg-0"Creating an LVM Volume Group with selection of all devices on the node (using matchLabels):
apiVersion: storage.deckhouse.io/v1alpha1
kind: LVMVolumeGroup
metadata:
name: "vg-0-on-node-0"
spec:
type: Local
local:
nodeName: "node-0"
blockDeviceSelector:
matchLabels:
kubernetes.io/hostname: node-0
actualVGNameOnTheNode: "vg-0"Examples with thin pool:
Creating an LVM Volume Group with thin pool and selection of specific devices by names (using matchExpressions):
apiVersion: storage.deckhouse.io/v1alpha1
kind: LVMVolumeGroup
metadata:
name: "vg-0-on-node-0"
spec:
type: Local
local:
nodeName: "node-0"
blockDeviceSelector:
matchExpressions:
- key: kubernetes.io/metadata.name
operator: In
values:
- dev-07ad52cef2348996b72db262011f1b5f896bb68f
- dev-e90e8915902bd6c371e59f89254c0fd644126da7
actualVGNameOnTheNode: "vg-0"
thinPools:
- name: thin-1
size: 250GiCreating an LVM Volume Group with thin pool and selection of all devices on the node (using matchLabels):
apiVersion: storage.deckhouse.io/v1alpha1
kind: LVMVolumeGroup
metadata:
name: "vg-0-on-node-0"
spec:
type: Local
local:
nodeName: "node-0"
blockDeviceSelector:
matchLabels:
kubernetes.io/hostname: node-0
actualVGNameOnTheNode: "vg-0"
thinPools:
- name: thin-1
size: 250GiYou can use any convenient selectors for BlockDevice resources. For example, select all devices on a node (using matchLabels) or part of devices by specifying their names or other parameters.
The spec.local field is mandatory for the Local type. If there’s a discrepancy between the name in spec.local.nodeName and selectors, LVMVolumeGroup creation will not be executed.
All selected block devices must belong to the same node for LVMVolumeGroup with type Local.
Creating an LVMVolumeGroup with file-backed devices
When dedicated block devices are not available, you can allocate part of an existing filesystem for LVM by using file-backed devices (spec.fileDevices). The agent will create a preallocated file, attach it as a loop device, and use it as an LVM Physical Volume.
Each spec.fileDevices[].directory must be inside the base directory configured by the fileDevicesDirectory module setting (default /var/lib/deckhouse/sds/file-devices); the agent rejects paths outside it so a stray entry cannot fill an arbitrary host path. To place backing files on a dedicated data disk, mount the disk on the node and set fileDevicesDirectory to its mount point in the module configuration.
Creating a Volume Group backed by a 50Gi file on an existing filesystem:
apiVersion: storage.deckhouse.io/v1alpha1
kind: LVMVolumeGroup
metadata:
name: "vg-file-on-node-0"
spec:
type: Local
local:
nodeName: "node-0"
actualVGNameOnTheNode: "vg-file"
fileDevices:
- name: data-0
directory: /var/lib/deckhouse/sds/file-devices
size: 50GiCombining block devices and file-backed devices in a single Volume Group:
apiVersion: storage.deckhouse.io/v1alpha1
kind: LVMVolumeGroup
metadata:
name: "vg-mixed-on-node-0"
spec:
type: Local
local:
nodeName: "node-0"
blockDeviceSelector:
matchExpressions:
- key: kubernetes.io/metadata.name
operator: In
values:
- dev-07ad52cef2348996b72db262011f1b5f896bb68f
actualVGNameOnTheNode: "vg-mixed"
fileDevices:
- name: data-0
directory: /var/lib/deckhouse/sds/file-devices
size: 100GiFile-backed devices add overhead due to double indirection (LVM on loop device on filesystem). Use them only when dedicated block devices are not available.
Growing a file-backed Volume Group
The straightforward way is to raise the size of an existing entry:
fileDevices:
- name: data-0
directory: /var/lib/deckhouse/sds/file-devices
size: 100Gi # was 50GiThe agent grows the backing file, tells the loop device to re-read it and resizes the Physical Volume. All three steps run online: nothing is unmounted, no logical volume is deactivated, and volumes in use keep working throughout. A thin pool sized as a percentage of the Volume Group follows automatically.
size can only be increased. Lowering it is rejected at admission: returning capacity means shrinking the Volume Group (pvmove + vgreduce), which can be impossible when the remaining Physical Volumes have no room and is destructive when it is not. For block devices the module only removes a Physical Volume that is already empty, see Extracting a BlockDevice resource from LVMVolumeGroup.
When the extra capacity has to come from a different filesystem, add a new entry instead:
fileDevices:
- name: data-0 # unchanged
directory: /var/lib/deckhouse/sds/file-devices
size: 50Gi
- name: data-1 # new file, new loop device, new PV
directory: /mnt/second-disk/sds-file-devices
size: 50GiEntries are distinguished by name, so several entries of the same size may share a directory.
An entry that has not been provisioned — it is absent from status.nodes[].fileDevices, for example because the agent rejected it — can be removed from the spec. Removing an entry that backs a live Physical Volume is not supported: the module never shrinks a Volume Group. The agent reports such a removal on the VGConfigurationApplied condition and leaves the Physical Volume in place; restore the entry, or remove the Physical Volume manually with pvmove + vgreduce + pvremove.
Prefer raising an existing entry over adding entries: at most 32 are allowed, and every one of them costs a loop device, a Physical Volume and Volume Group metadata. Thick logical volumes requesting contiguous space also become harder to place as free space is spread across many small Physical Volumes.
The agent automatically recovers loop device mappings after a node reboot.
To reclaim space taken by deleted data without changing any size, use fstrim — see the FAQ.
Updating an LVMVolumeGroup resource
To change the desired state of a Volume Group or thin pool on nodes, modify the spec field of the corresponding LVMVolumeGroup resource. The controller automatically validates the new data and, if correct, makes the necessary changes to entities on the node.
The controller automatically updates the status field of the LVMVolumeGroup resource, displaying current data about the corresponding LVM Volume Group on the node. It is not recommended to manually modify the status field.
The controller does not modify the spec field, as it reflects the desired state of the LVM Volume Group. To change the state of the corresponding LVM Volume Group on the node, the user can modify the spec field.
Adding capacity on a node used by a LocalStorageClass
A LocalStorageClass accepts only one LVMVolumeGroup per node. Several LVMVolumeGroup resources may exist on the same node, but each of them must be used in a different LocalStorageClass. If a LocalStorageClass lists two LVMVolumeGroup resources from the same node, it goes to the Failed phase with the following reason:
Some LVMVolumeGroups use the same node (|node: LVG names): |node1: vg-1-on-node1,vg-2-on-node1,The restriction exists for two reasons:
- A volume of the storage class is placed by node: the CSI driver picks the single LVMVolumeGroup of the class on the node selected by the scheduler.
- Separate Volume Groups do not share free space. Thin volumes in a thin pool of one Volume Group cannot grow into another Volume Group, even when it has free space.
To add capacity on such a node, extend the Volume Group that is already in the LocalStorageClass instead of creating a new LVMVolumeGroup resource: change spec.blockDeviceSelector of the existing LVMVolumeGroup so that it also selects the new BlockDevice resource. The controller adds the device to the Volume Group. A thin pool whose size is set as a percentage grows together with the Volume Group; for a thin pool with an absolute size, increase the value in spec.thinPools.
Deleting an LVMVolumeGroup resource
Automatic deletion
The controller automatically deletes the resource if the Volume Group specified in it becomes unavailable (for example, all block devices that made up the Volume Group were disconnected on the node).
Manual deletion
The user can delete the LVM Volume Group on the node along with the associated LVM Physical Volumes by deleting the LVMVolumeGroup resource:
d8 k delete lvg %lvg-name%Deletion protection
The user can prevent deletion of the LVMVolumeGroup resource by adding the storage.deckhouse.io/deletion-protection annotation to the resource. If this annotation is present, the controller will not delete either the resource or the corresponding Volume Group until the annotation is removed from the resource.
If the deleting LVMVolumeGroup resource contains a Logical Volume (even if it’s only a thin pool specified in spec), you must manually delete all Logical Volumes in the Volume Group being deleted. Otherwise, neither the resource nor the Volume Group will be deleted.
Extracting a BlockDevice resource from LVMVolumeGroup
To extract a BlockDevice resource from an LVMVolumeGroup resource, do the following:
- Modify the
spec.blockDeviceSelectorfield of the LVMVolumeGroup resource (add other selectors) or modify the corresponding labels on the BlockDevice resource so they no longer match the LVMVolumeGroup selectors. - If the Physical Volume of the device holds data, move it off with
pvmove <device>on the node. The module never moves data. - Remove the empty Physical Volume from the Volume Group. Either let the agent do it (see below) or run
vgreduce <vg> <device>andpvremove <device>on the node.
By default, the agent does not remove anything. While a device that has left the selector is still in the Volume Group, the VGConfigurationApplied condition is False with the reason ValidationFailed, and the Volume Group is not extended further. The message of the condition names the device and what is in the way: the amount of data on its Physical Volume and the pvmove to run, or, if the Physical Volume is empty, the spec.releaseEmptyBlockDevices field. While the field is false, the agent runs no LVM command for this message: it is built from the agent’s latest scan of the node and refreshed periodically.
Releasing empty Physical Volumes automatically
Set spec.releaseEmptyBlockDevices to true on the LVMVolumeGroup resource (or in spec.lvmVolumeGroupTemplate of an LVMVolumeGroupSet, from where it is copied to every LVMVolumeGroup of the set) to let the agent run vgreduce and pvremove for a device that has left blockDeviceSelector. The agent acts only when all of the following hold:
- The BlockDevice resource exists, its labels do not match
blockDeviceSelector, and it has noMissingcondition. A device that has disappeared from the node is not a device taken out of the selector, and the agent leaves it alone. - No other BlockDevice on the same node carries the same Physical Volume. Two BlockDevices with one Physical Volume mean that the device has changed its identity or is seen through another path, for example after its multipath map was removed, and not that it was taken out of the selector.
- The Physical Volume is found in LVM by the UUID recorded in the status of the resource, never by its path alone, and holds no data:
pv_usedis zero when it is read from LVM right beforevgreduce. - The Physical Volume belongs to the Volume Group of this resource, and the Volume Group carries the
storage.deckhouse.io/lvmVolumeGroupNametag with the name of this resource, is not shared (lvmlockd), is listed by LVM on this node (a Volume Group whose system ID belongs to another host is not), and keeps at least one other Physical Volume. The last Physical Volume is never removed. - No
pvmoveis running in the Volume Group. - No thin pool whose
sizeis a percentage would be larger than that percentage of the Volume Group without this Physical Volume (see below). - All of the above held on two reconciliation passes in a row, at least a minute apart, so that a label changed and changed back does not remove a disk.
A Physical Volume that still holds data is never touched, whatever the value of the field. vgreduce is run without --removemissing and --force, so LVM itself also refuses a Physical Volume that is in use. After pvmove ends, the agent notices the empty Physical Volume on its next retry and removes it.
A Physical Volume that is in no Volume Group is not removed automatically, even if its device was in this resource before: the condition names it, and pvremove is run by hand. This is also the state left behind when vgreduce went through and pvremove failed.
Enable the field only with a blockDeviceSelector on labels that stay with the device, such as labels you set on the BlockDevice resources yourself. Do not select by the status.blockdevice.storage.deckhouse.io/* labels: the agent changes them itself when the state of the device changes, and the device then leaves the selector without anyone asking for it. A device that changes its identity gets a new BlockDevice, which neither the labels set on the old one nor its name select: while the old BlockDevice exists, the agent refuses to act, and after it is deleted, an empty Physical Volume of such a device is released.
The field applies to block devices only. A file device is changed through spec.fileDevices, see the FAQ.
Thin pools are never shrunk. A thin pool whose size is a percentage is checked against the Volume Group without the Physical Volume: if the thin pool is already larger than its percentage of the smaller Volume Group, the resource would fail validation after vgreduce, so the agent does not remove the Physical Volume and the condition names the thin pool. To release such a device, first set the size of the thin pool to an absolute value no smaller than its current size. Otherwise, only the free space of the Volume Group becomes smaller.
Protection against data leakage between volumes
When deleting files, the operating system does not physically delete the contents, but only marks the corresponding blocks as “free”. If a new volume receives physical blocks previously used by another volume, the previous user’s data may remain in them.
Data leakage problem
Data leakage is possible under the following conditions:
- User #1 created a volume from StorageClass 1 on node 1 (mode “Block” or “Filesystem” doesn’t matter), placed data in it, and then deleted the volume.
- Physical blocks occupied by user #1 are marked as free, but their contents are not cleared.
- User #2 requests a new volume from the same StorageClass 1 on the same node 1 in “Block” mode.
- When allocating volumes, the system may provide the same physical blocks that user #1 previously used.
- User #2 gets access to user #1’s data that remained in these blocks.
Thick volumes
To prevent leaks through thick volumes, the volumeCleanup parameter is provided, which allows you to select the volume cleanup method before deleting the Physical Volume.
Available cleanup methods
-
Parameter not specified — no additional actions are performed when deleting a volume. Data may remain available to the next user who gets the same volume.
-
RandomFillSinglePass— the volume will be overwritten with random data once before deletion. Not recommended for solid-state drives as it reduces the drive lifespan. -
RandomFillThreePass— the volume will be overwritten with random data three times before deletion. Not recommended for solid-state drives as it reduces the drive lifespan. -
Discard— all volume blocks will be marked as free using thediscardsystem call before deletion. This option is only applicable to solid-state drives.
Recommendations for using Discard
Most modern solid-state drives guarantee that after executing the discard command, a block will not return previous data when read. This makes the Discard option the most effective way to prevent data leakage when using solid-state drives.
The following limitations should be considered:
- Cell clearing is a relatively long operation, so it’s performed by the device in the background.
- Many drives cannot clear individual cells, only groups of cells (pages).
- Not all drives guarantee immediate unavailability of freed data.
- Not all drives that claim such guarantees actually meet them in practice.
It’s not recommended to use drives that don’t guarantee Deterministic TRIM (DRAT) and Deterministic Read Zero after TRIM (RZAT) or haven’t been tested for compliance with these standards.
Thin volumes
When a thin volume block is released via discard by the guest operating system, the command is passed to the physical device. When using a hard disk drive or when there’s no discard support on the solid-state drive, data may remain in the thin pool until the block is reused by another volume.
Users only have access to thin volumes, not the thin pool itself. When allocating a new volume from the pool for thin volumes, LVM performs zeroing of the thin pool block before using it. This prevents data leakage between clients and is guaranteed by the thin_pool_zero=1 setting in LVM.