2022-11-07 23:28:17 +00:00
|
|
|
# Local Static Storage Provisioner
|
2017-11-01 14:25:35 +00:00
|
|
|
|
2022-11-07 23:28:17 +00:00
|
|
|
The [local static storage provisioner](https://github.com/kubernetes-sigs/sig-storage-local-static-provisioner)
|
2019-01-08 20:36:44 +00:00
|
|
|
is NOT a dynamic storage provisioner as you would
|
2017-11-01 14:25:35 +00:00
|
|
|
expect from a cloud provider. Instead, it simply creates PersistentVolumes for
|
2022-11-07 23:28:17 +00:00
|
|
|
all mounts under the `host_dir` of the specified storage class.
|
2019-01-08 23:32:39 +00:00
|
|
|
These storage classes are specified in the `local_volume_provisioner_storage_classes` nested dictionary.
|
2022-11-07 23:28:17 +00:00
|
|
|
|
2019-01-08 23:32:39 +00:00
|
|
|
Example:
|
2019-01-08 20:36:44 +00:00
|
|
|
|
|
|
|
```yaml
|
|
|
|
local_volume_provisioner_storage_classes:
|
2019-01-08 23:32:39 +00:00
|
|
|
local-storage:
|
|
|
|
host_dir: /mnt/disks
|
|
|
|
mount_dir: /mnt/disks
|
|
|
|
fast-disks:
|
|
|
|
host_dir: /mnt/fast-disks
|
|
|
|
mount_dir: /mnt/fast-disks
|
|
|
|
block_cleaner_command:
|
2022-11-07 23:28:17 +00:00
|
|
|
- "/scripts/shred.sh"
|
|
|
|
- "2"
|
2019-01-08 23:32:39 +00:00
|
|
|
volume_mode: Filesystem
|
|
|
|
fs_type: ext4
|
2019-01-08 20:36:44 +00:00
|
|
|
```
|
|
|
|
|
2022-11-07 23:28:17 +00:00
|
|
|
For each key in `local_volume_provisioner_storage_classes` a "storage class" with
|
|
|
|
the same name is created in the entry `storageClassMap` of the ConfigMap `local-volume-provisioner`.
|
|
|
|
The subkeys of each storage class in `local_volume_provisioner_storage_classes`
|
|
|
|
are converted to camelCase and added as attributes to the storage class in the
|
|
|
|
ConfigMap.
|
|
|
|
|
2019-01-08 20:36:44 +00:00
|
|
|
The result of the above example is:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
data:
|
|
|
|
storageClassMap: |
|
|
|
|
local-storage:
|
2019-01-08 23:32:39 +00:00
|
|
|
hostDir: /mnt/disks
|
|
|
|
mountDir: /mnt/disks
|
2019-01-08 20:36:44 +00:00
|
|
|
fast-disks:
|
2019-01-08 23:32:39 +00:00
|
|
|
hostDir: /mnt/fast-disks
|
|
|
|
mountDir: /mnt/fast-disks
|
|
|
|
blockCleanerCommand:
|
|
|
|
- "/scripts/shred.sh"
|
|
|
|
- "2"
|
|
|
|
volumeMode: Filesystem
|
|
|
|
fsType: ext4
|
2019-01-08 20:36:44 +00:00
|
|
|
```
|
|
|
|
|
2022-11-07 23:28:17 +00:00
|
|
|
Additionally, a StorageClass object (`storageclasses.storage.k8s.io`) is also
|
|
|
|
created for each storage class:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ kubectl get storageclasses.storage.k8s.io
|
|
|
|
NAME PROVISIONER RECLAIMPOLICY
|
|
|
|
fast-disks kubernetes.io/no-provisioner Delete
|
|
|
|
local-storage kubernetes.io/no-provisioner Delete
|
|
|
|
```
|
|
|
|
|
|
|
|
The default StorageClass is `local-storage` on `/mnt/disks`;
|
|
|
|
the rest of this documentation will use that path as an example.
|
2017-11-01 14:25:35 +00:00
|
|
|
|
2021-06-01 14:30:27 +00:00
|
|
|
## Examples to create local storage volumes
|
2017-11-01 14:25:35 +00:00
|
|
|
|
2022-11-07 23:28:17 +00:00
|
|
|
1. Using tmpfs
|
2017-11-01 14:25:35 +00:00
|
|
|
|
2022-11-07 23:28:17 +00:00
|
|
|
```bash
|
|
|
|
for vol in vol1 vol2 vol3; do
|
|
|
|
mkdir /mnt/disks/$vol
|
|
|
|
mount -t tmpfs -o size=5G $vol /mnt/disks/$vol
|
|
|
|
done
|
|
|
|
```
|
2017-11-01 14:25:35 +00:00
|
|
|
|
2022-11-07 23:28:17 +00:00
|
|
|
The tmpfs method is not recommended for production because the mounts are not
|
|
|
|
persistent and data will be deleted on reboot.
|
2017-11-01 14:25:35 +00:00
|
|
|
|
2020-12-30 13:07:49 +00:00
|
|
|
1. Mount physical disks
|
2017-11-01 14:25:35 +00:00
|
|
|
|
2022-11-07 23:28:17 +00:00
|
|
|
```bash
|
|
|
|
mkdir /mnt/disks/ssd1
|
|
|
|
mount /dev/vdb1 /mnt/disks/ssd1
|
|
|
|
```
|
2017-11-01 14:25:35 +00:00
|
|
|
|
2022-11-07 23:28:17 +00:00
|
|
|
Physical disks are recommended for production environments because it offers
|
|
|
|
complete isolation in terms of I/O and capacity.
|
2017-11-01 14:25:35 +00:00
|
|
|
|
2020-12-30 13:07:49 +00:00
|
|
|
1. Mount unpartitioned physical devices
|
2019-07-16 12:27:26 +00:00
|
|
|
|
2022-11-07 23:28:17 +00:00
|
|
|
```bash
|
|
|
|
for disk in /dev/sdc /dev/sdd /dev/sde; do
|
|
|
|
ln -s $disk /mnt/disks
|
|
|
|
done
|
|
|
|
```
|
2019-07-16 12:27:26 +00:00
|
|
|
|
2022-11-07 23:28:17 +00:00
|
|
|
This saves time of precreating filesystems. Note that your storageclass must have
|
|
|
|
`volume_mode` set to `"Filesystem"` and `fs_type` defined. If either is not set, the
|
|
|
|
disk will be added as a raw block device.
|
2019-07-16 12:27:26 +00:00
|
|
|
|
2022-11-07 23:28:17 +00:00
|
|
|
1. PersistentVolumes with `volumeMode="Block"`
|
2017-11-01 14:25:35 +00:00
|
|
|
|
2022-11-07 23:28:17 +00:00
|
|
|
Just like above, you can create PersistentVolumes with volumeMode `Block`
|
|
|
|
by creating a symbolic link under discovery directory to the block device on
|
|
|
|
the node, if you set `volume_mode` to `"Block"`. This will create a volume
|
|
|
|
presented into a Pod as a block device, without any filesystem on it.
|
2017-11-01 14:25:35 +00:00
|
|
|
|
2022-11-07 23:28:17 +00:00
|
|
|
1. File-backed sparsefile method
|
2017-11-01 14:25:35 +00:00
|
|
|
|
2022-11-07 23:28:17 +00:00
|
|
|
```bash
|
|
|
|
truncate /mnt/disks/disk5 --size 2G
|
|
|
|
mkfs.ext4 /mnt/disks/disk5
|
|
|
|
mkdir /mnt/disks/vol5
|
|
|
|
mount /mnt/disks/disk5 /mnt/disks/vol5
|
|
|
|
```
|
2018-02-15 01:55:43 +00:00
|
|
|
|
2022-11-07 23:28:17 +00:00
|
|
|
If you have a development environment and only one disk, this is the best way
|
|
|
|
to limit the quota of persistent volumes.
|
2017-11-01 14:25:35 +00:00
|
|
|
|
2022-11-07 23:28:17 +00:00
|
|
|
1. Simple directories
|
2018-08-10 14:14:34 +00:00
|
|
|
|
2022-11-07 23:28:17 +00:00
|
|
|
In a development environment, using `mount --bind` works also, but there is no capacity
|
|
|
|
management.
|
2018-08-10 14:14:34 +00:00
|
|
|
|
2021-06-01 14:30:27 +00:00
|
|
|
## Usage notes
|
2017-11-01 14:25:35 +00:00
|
|
|
|
2022-11-07 23:28:17 +00:00
|
|
|
Make sure to make any mounts persist via `/etc/fstab` or with systemd mounts (for
|
|
|
|
Flatcar Container Linux or Fedora CoreOS). Pods with persistent volume claims will not be
|
2017-11-01 14:25:35 +00:00
|
|
|
able to start if the mounts become unavailable.
|
|
|
|
|
2021-06-01 14:30:27 +00:00
|
|
|
## Further reading
|
2017-11-01 14:25:35 +00:00
|
|
|
|
2022-11-07 23:28:17 +00:00
|
|
|
Refer to the upstream docs here: <https://github.com/kubernetes-sigs/sig-storage-local-static-provisioner>
|