Here are the steps to enable and test the Kubernetes Volume Snaphot subsystem on Rancher RKE or RKE2.
Deploying the volume snapshot controller and CRDs is required for managing snapshots for storage providers such as Longhorn, Rook/Ceph via the native K8s API as well as for integrating Rancher-managed clusters with backup solutions like Kasten K10.
export SNAPSHOT_CTRL_VER=v5.0.1
git clone -b $SNAPSHOT_CTRL_VER https://github.com/kubernetes-csi/external-snapshotter.git
cd external-snapshotter
kubectl kustomize client/config/crd | kubectl create -f -
kubectl -n kube-system kustomize deploy/kubernetes/snapshot-controller | kubectl create -f -
kubectl -n kube-system rollout status deploy/snapshot-controller
See: https://longhorn.io/docs/1.2.3/deploy/install/
Ensure the Snapshot CRDs are available:
kubectl -n kube-system wait --for condition=established --timeout=60s crd/volumesnapshotclasses.snapshot.storage.k8s.io
Create a default Snapshot Class, for example for Longhorn:
K8s 1.21+
cat <<K8S | kubectl apply -f -
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshotClass
metadata:
name: longhorn
driver: driver.longhorn.io
deletionPolicy: Delete
K8S
K8s 1.20
cat <<K8S | kubectl apply -f -
apiVersion: snapshot.storage.k8s.io/v1beta1
kind: VolumeSnapshotClass
metadata:
name: longhorn
driver: driver.longhorn.io
deletionPolicy: Delete
K8S
For example:
cat <<K8S | kubectl apply -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: test-pvc
spec:
accessModes:
- ReadWriteOnce
storageClassName: longhorn
resources:
requests:
storage: 1Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-stateful-world
spec:
selector:
matchLabels:
app: hello-world
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-world
image: busybox
command: ['sh', '-c', 'echo "Hello World!" >/srv/hello/hello.txt && sleep 3600']
volumeMounts:
- name: test-volume
mountPath: /srv/hello/
volumes:
- name: test-volume
persistentVolumeClaim:
claimName: test-pvc
K8S
Wait for the Pod:
kubectl rollout status deploy/hello-stateful-world
Create the snapshot CR:
v1.21+
cat <<K8S | kubectl apply -f -
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: test-snapshot
spec:
volumeSnapshotClassName: longhorn
source:
persistentVolumeClaimName: test-pvc
K8S
v1.20
cat <<K8S | kubectl apply -f -
apiVersion: snapshot.storage.k8s.io/v1beta1
kind: VolumeSnapshot
metadata:
name: test-snapshot
spec:
volumeSnapshotClassName: longhorn
source:
persistentVolumeClaimName: test-pvc
K8S
kubectl get volumesnapshotcontents --watch