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.

122 lines
3.5 KiB

  1. # Local Storage Provisioner
  2. The [local storage provisioner](https://github.com/kubernetes-incubator/external-storage/tree/master/local-volume)
  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 storageClass with the
  23. same name is created. The subkeys of each storage class are converted to camelCase and added
  24. as attributes to the storageClass.
  25. The result of the above example is:
  26. ```yaml
  27. data:
  28. storageClassMap: |
  29. local-storage:
  30. hostDir: /mnt/disks
  31. mountDir: /mnt/disks
  32. fast-disks:
  33. hostDir: /mnt/fast-disks
  34. mountDir: /mnt/fast-disks
  35. blockCleanerCommand:
  36. - "/scripts/shred.sh"
  37. - "2"
  38. volumeMode: Filesystem
  39. fsType: ext4
  40. ```
  41. The default StorageClass is local-storage on /mnt/disks,
  42. the rest of this doc will use that path as an example.
  43. ## Examples to create local storage volumes
  44. 1. tmpfs method:
  45. ``` bash
  46. for vol in vol1 vol2 vol3; do
  47. mkdir /mnt/disks/$vol
  48. mount -t tmpfs -o size=5G $vol /mnt/disks/$vol
  49. done
  50. ```
  51. The tmpfs method is not recommended for production because the mount is not
  52. persistent and data will be deleted on reboot.
  53. 1. Mount physical disks
  54. ``` bash
  55. mkdir /mnt/disks/ssd1
  56. mount /dev/vdb1 /mnt/disks/ssd1
  57. ```
  58. Physical disks are recommended for production environments because it offers
  59. complete isolation in terms of I/O and capacity.
  60. 1. Mount unpartitioned physical devices
  61. ``` bash
  62. for disk in /dev/sdc /dev/sdd /dev/sde; do
  63. ln -s $disk /mnt/disks
  64. done
  65. ```
  66. This saves time of precreating filesystems. Note that your storageclass must have
  67. volume_mode set to "Filesystem" and fs_type defined. If either is not set, the
  68. disk will be added as a raw block device.
  69. 1. File-backed sparsefile method
  70. ``` bash
  71. truncate /mnt/disks/disk5 --size 2G
  72. mkfs.ext4 /mnt/disks/disk5
  73. mkdir /mnt/disks/vol5
  74. mount /mnt/disks/disk5 /mnt/disks/vol5
  75. ```
  76. If you have a development environment and only one disk, this is the best way
  77. to limit the quota of persistent volumes.
  78. 1. Simple directories
  79. In a development environment using `mount --bind` works also, but there is no capacity
  80. management.
  81. 1. Block volumeMode PVs
  82. Create a symbolic link under discovery directory to the block device on the node. To use
  83. raw block devices in pods, volume_type should be set to "Block".
  84. ## Usage notes
  85. Beta PV.NodeAffinity field is used by default. If running against an older K8s
  86. version, the useAlphaAPI flag must be set in the configMap.
  87. The volume provisioner cannot calculate volume sizes correctly, so you should
  88. delete the daemonset pod on the relevant host after creating volumes. The pod
  89. will be recreated and read the size correctly.
  90. Make sure to make any mounts persist via /etc/fstab or with systemd mounts (for
  91. Flatcar Container Linux). Pods with persistent volume claims will not be
  92. able to start if the mounts become unavailable.
  93. ## Further reading
  94. Refer to the upstream docs here: <https://github.com/kubernetes-incubator/external-storage/tree/master/local-volume>