Persistent volumes
Last modified Apr 20, 2023
Normally when you wish to persist data inside of kubernetes you need to create a volume, and mount it into your container. With StorageClasses it can be done alittle bit smarter. StorageClasses contains a provisioner which is used to automatically provision volumes. So insted of specificing a path somewhere on the host-machine, you create a persistentvolumeclaim, that contains which storageclass that should provision the volume.
Longhorn offers such a storageclass mentioned above. Longhorn also do alot of other things with the volumes to ensure availability. Longhorn will automatically replicate all volumes to multiple machines, so in case a host-machine fails, the volume will still be available on other machines. Furthermore Longhorn offers easy ways to create backups of volumes.
This means that you can create a persistentvolumeclaim like;
|
|
When this is applied, the storageClass will use its provisioner to provision the requested volume.
The access modes possible are:
- ReadWriteOnce – the volume can be mounted as read-write by a single node
- ReadOnlyMany – the volume can be mounted read-only by many nodes
- ReadWriteMany – the volume can be mounted as read-write by many nodes
- ReadWriteOncePod – the volume can be mounted as read-write by a single Pod. This is only supported for CSI volumes and Kubernetes version 1.22+.
When a persistentVolumeClaim are created, you can fx mount it, when creating a deployment like this;
|
|
Kithosting