You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
3.9 KiB

  1. # Local Static Storage Provisioner
  2. The [local static storage provisioner](https://github.com/kubernetes-sigs/sig-storage-local-static-provisioner)
  3. is NOT a dynamic storage provisioner as you would
  4. expect from a cloud provider. Instead, it simply creates PersistentVolumes for
  5. all mounts under the `host_dir` of the specified storage class.
  6. These storage classes are specified in the `local_volume_provisioner_storage_classes` nested dictionary.
  7. Example:
  8. ```yaml
  9. local_volume_provisioner_storage_classes:
  10. local-storage:
  11. host_dir: /mnt/disks
  12. mount_dir: /mnt/disks
  13. fast-disks:
  14. host_dir: /mnt/fast-disks
  15. mount_dir: /mnt/fast-disks
  16. block_cleaner_command:
  17. - "/scripts/shred.sh"
  18. - "2"
  19. volume_mode: Filesystem
  20. fs_type: ext4
  21. ```
  22. For each key in `local_volume_provisioner_storage_classes` a "storage class" with
  23. the same name is created in the entry `storageClassMap` of the ConfigMap `local-volume-provisioner`.
  24. The subkeys of each storage class in `local_volume_provisioner_storage_classes`
  25. are converted to camelCase and added as attributes to the storage class in the
  26. ConfigMap.
  27. The result of the above example is:
  28. ```yaml
  29. data:
  30. storageClassMap: |
  31. local-storage:
  32. hostDir: /mnt/disks
  33. mountDir: /mnt/disks
  34. fast-disks:
  35. hostDir: /mnt/fast-disks
  36. mountDir: /mnt/fast-disks
  37. blockCleanerCommand:
  38. - "/scripts/shred.sh"
  39. - "2"
  40. volumeMode: Filesystem
  41. fsType: ext4
  42. ```
  43. Additionally, a StorageClass object (`storageclasses.storage.k8s.io`) is also
  44. created for each storage class:
  45. ```bash
  46. $ kubectl get storageclasses.storage.k8s.io
  47. NAME PROVISIONER RECLAIMPOLICY
  48. fast-disks kubernetes.io/no-provisioner Delete
  49. local-storage kubernetes.io/no-provisioner Delete
  50. ```
  51. The default StorageClass is `local-storage` on `/mnt/disks`;
  52. the rest of this documentation will use that path as an example.
  53. ## Examples to create local storage volumes
  54. 1. Using tmpfs
  55. ```bash
  56. for vol in vol1 vol2 vol3; do
  57. mkdir /mnt/disks/$vol
  58. mount -t tmpfs -o size=5G $vol /mnt/disks/$vol
  59. done
  60. ```
  61. The tmpfs method is not recommended for production because the mounts are not
  62. persistent and data will be deleted on reboot.
  63. 1. Mount physical disks
  64. ```bash
  65. mkdir /mnt/disks/ssd1
  66. mount /dev/vdb1 /mnt/disks/ssd1
  67. ```
  68. Physical disks are recommended for production environments because it offers
  69. complete isolation in terms of I/O and capacity.
  70. 1. Mount unpartitioned physical devices
  71. ```bash
  72. for disk in /dev/sdc /dev/sdd /dev/sde; do
  73. ln -s $disk /mnt/disks
  74. done
  75. ```
  76. This saves time of precreating filesystems. Note that your storageclass must have
  77. `volume_mode` set to `"Filesystem"` and `fs_type` defined. If either is not set, the
  78. disk will be added as a raw block device.
  79. 1. PersistentVolumes with `volumeMode="Block"`
  80. Just like above, you can create PersistentVolumes with volumeMode `Block`
  81. by creating a symbolic link under discovery directory to the block device on
  82. the node, if you set `volume_mode` to `"Block"`. This will create a volume
  83. presented into a Pod as a block device, without any filesystem on it.
  84. 1. File-backed sparsefile method
  85. ```bash
  86. truncate /mnt/disks/disk5 --size 2G
  87. mkfs.ext4 /mnt/disks/disk5
  88. mkdir /mnt/disks/vol5
  89. mount /mnt/disks/disk5 /mnt/disks/vol5
  90. ```
  91. If you have a development environment and only one disk, this is the best way
  92. to limit the quota of persistent volumes.
  93. 1. Simple directories
  94. In a development environment, using `mount --bind` works also, but there is no capacity
  95. management.
  96. ## Usage notes
  97. Make sure to make any mounts persist via `/etc/fstab` or with systemd mounts (for
  98. Flatcar Container Linux or Fedora CoreOS). Pods with persistent volume claims will not be
  99. able to start if the mounts become unavailable.
  100. ## Further reading
  101. Refer to the upstream docs here: <https://github.com/kubernetes-sigs/sig-storage-local-static-provisioner>