See also the proposal of the functionality.
You need to create a thin pool of LVM beforehand, because TopoLVM doesn't create one. For example:
lvcreate -T -n pool0 -L 4G myvg1
You also need to install the CRDs and the controller for volume snapshots. Please follow the official document to install them.
Change your lvmd settings to use the thin pool you've created. For example, if you are using the Helm charts, modify your values.yaml as follows:
lvmd:
deviceClasses:
# ...
# Other device classes are here.
# ...
- name: "thin"
volume-group: "myvg1"
type: thin
thin-pool:
name: "pool0"
overprovision-ratio: 5.0
Create a storage class for the DeviceClass for the thin pool. For example, if you are using the Helm charts, modify your values.yaml as follows:
storageClasses:
# ...
# Other storage classes are here.
# ...
- name: topolvm-provisioner-thin
storageClass:
fsType: xfs
isDefaultClass: false
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: true
additionalParameters:
'{{ include "topolvm.pluginName" . }}/device-class': "thin"
Deploy TopoLVM with the settings you updated above. See also the Getting Started guide.
Run the following command to deploy my-pvc
and my-pod
, which use topolvm-provisioner-thin
.
kubectl apply -f - <<EOF
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: my-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: topolvm-provisioner-thin
---
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
- name: pause
image: ubuntu:22.04
command:
- bash
- -c
- |
sleep infinity
volumeMounts:
- mountPath: /data
name: volume
volumes:
- name: volume
persistentVolumeClaim:
claimName: my-pvc
EOF
Write some data to the volume:
$ kubectl exec -it my-pod -- bash
root@my-pod:/# echo hello > /data/world
root@my-pod:/# ls /data/world
/data/world
root@my-pod:/# cat /data/world
hello
Before taking snapshots, you need to prepare VolumeSnapshotClass
as follows:
kubectl apply -f - <<EOF
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshotClass
metadata:
name: topolvm-provisioner-thin
driver: topolvm.io
deletionPolicy: Delete
EOF
Then run the following command to take a snapshot:
kubectl apply -f - <<EOF
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: my-snapshot
spec:
volumeSnapshotClassName: topolvm-provisioner-thin
source:
persistentVolumeClaimName: my-pvc
EOF
Run the following command to restore a PV from the snapshot taken above:
kubectl apply -f - <<EOF
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: my-pvc2
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: topolvm-provisioner-thin
dataSource:
name: my-snapshot
kind: VolumeSnapshot
apiGroup: snapshot.storage.k8s.io
---
apiVersion: v1
kind: Pod
metadata:
name: my-pod2
spec:
containers:
- name: pause
image: ubuntu:22.04
command:
- bash
- -c
- |
sleep infinity
volumeMounts:
- mountPath: /data
name: volume
volumes:
- name: volume
persistentVolumeClaim:
claimName: my-pvc2
EOF
And check the content of the volume:
$ kubectl exec -it my-pod2 -- cat /data/world
hello