Skip to content

doc: add snapshot feature doc #557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Please refer to [`nfs.csi.k8s.io` driver parameters](./docs/driver-parameters.md
### Examples
- [Basic usage](./deploy/example/README.md)
- [fsGroupPolicy](./deploy/example/fsgroup)
- [Snapshot](./deploy/example/snapshot)
- [Volume cloning](./deploy/example/cloning)

### Troubleshooting
Expand Down
76 changes: 76 additions & 0 deletions deploy/example/snapshot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Volume Snapshot Example

- supported from v4.3.0

## Create source PVC and an example pod to write data

```console
kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/master/deploy/example/storageclass-nfs.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/master/deploy/example/pvc-nfs-csi-dynamic.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/master/deploy/example/nginx-pod-nfs.yaml
```

### Check the Source PVC

```console
$ kubectl exec nginx-nfs -- ls /mnt/nfs
outfile
```

## Create a snapshot on source PVC
```console
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/csi-driver-nfs/master/deploy/example/snapshot/snapshotclass-nfs.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/csi-driver-nfs/master/deploy/example/snapshot/snapshot-nfs-dynamic.yaml
```
- Check snapshot Status

```console
$ kubectl describe volumesnapshot test-nfs-snapshot
Name: test-nfs-snapshot
Namespace: default
Labels: <none>
Annotations: <none>
API Version: snapshot.storage.k8s.io/v1
Kind: VolumeSnapshot
Metadata:
Creation Timestamp: 2023-12-01T06:37:55Z
Finalizers:
snapshot.storage.kubernetes.io/volumesnapshot-as-source-protection
snapshot.storage.kubernetes.io/volumesnapshot-bound-protection
Generation: 1
Resource Version: 3901120
UID: 9a159fca-4824-4053-8d90-a92c25fb860f
Spec:
Source:
Persistent Volume Claim Name: pvc-nfs-dynamic
Volume Snapshot Class Name: csi-nfs-snapclass
Status:
Bound Volume Snapshot Content Name: snapcontent-9a159fca-4824-4053-8d90-a92c25fb860f
Creation Time: 2023-12-01T06:37:57Z
Ready To Use: true
Restore Size: 656257
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal CreatingSnapshot 22s snapshot-controller Waiting for a snapshot default/test-nfs-snapshot to be created by the CSI driver.
Normal SnapshotCreated 20s snapshot-controller Snapshot default/test-nfs-snapshot was successfully created by the CSI driver.
Normal SnapshotReady 20s snapshot-controller Snapshot default/test-nfs-snapshot is ready to use.
```
> In above example, `snapcontent-9a159fca-4824-4053-8d90-a92c25fb860f` is the snapshot name

## Create a new PVC based on snapshot

```console
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/csi-driver-nfs/master/deploy/example/snapshot/pvc-nfs-snapshot-restored.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/csi-driver-nfs/master/deploy/example/snapshot/nginx-pod-restored-snapshot.yaml
```

- Check data

```console
$ kubectl exec nginx-nfs-restored-snapshot -- ls /mnt/nfs
outfile
```

### Links
- [CSI Snapshotter](https://github.com/kubernetes-csi/external-snapshotter)
23 changes: 23 additions & 0 deletions deploy/example/snapshot/nginx-pod-restored-snapshot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
kind: Pod
apiVersion: v1
metadata:
name: nginx-nfs-restored-snapshot
spec:
nodeSelector:
"kubernetes.io/os": linux
containers:
- image: mcr.microsoft.com/oss/nginx/nginx:1.19.5
name: nginx-nfs
command:
- "/bin/bash"
- "-c"
- set -euo pipefail; while true; do echo $(date) >> /mnt/nfs/outfile; sleep 1; done
volumeMounts:
- name: persistent-storage
mountPath: "/mnt/nfs"
readOnly: false
volumes:
- name: persistent-storage
persistentVolumeClaim:
claimName: pvc-nfs-snapshot-restored
17 changes: 17 additions & 0 deletions deploy/example/snapshot/pvc-nfs-snapshot-restored.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-nfs-snapshot-restored
namespace: default
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Gi
storageClassName: nfs-csi
dataSource:
name: test-nfs-snapshot
kind: VolumeSnapshot
apiGroup: snapshot.storage.k8s.io
2 changes: 1 addition & 1 deletion hack/verify-yamllint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if [[ "${deployDirNum}" != "${helmDirNum}" ]]; then
exit 1
fi

for path in "deploy/*.yaml" "deploy/example/*.yaml" "deploy/example/nfs-provisioner/*.yaml" "deploy/example/cloning/*.yaml"
for path in "deploy/*.yaml" "deploy/example/*.yaml" "deploy/example/nfs-provisioner/*.yaml" "deploy/example/cloning/*.yaml" "deploy/example/snapshot/*.yaml"
do
echo "checking yamllint under path: $path ..."
yamllint -f parsable $path | grep -v "line too long" > $LOG
Expand Down
4 changes: 2 additions & 2 deletions test/external-e2e/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ setup_e2e_binaries() {

# test on alternative driver name
sed -i "s/nfs.csi.k8s.io/$DRIVER.csi.k8s.io/g" deploy/example/storageclass-nfs.yaml
sed -i "s/nfs.csi.k8s.io/$DRIVER.csi.k8s.io/g" deploy/example/snapshotclass-nfs.yaml
sed -i "s/nfs.csi.k8s.io/$DRIVER.csi.k8s.io/g" deploy/example/snapshot/snapshotclass-nfs.yaml
# install csi driver
mkdir -p /tmp/csi
cp deploy/example/storageclass-nfs.yaml /tmp/csi/storageclass.yaml
cp deploy/example/snapshotclass-nfs.yaml /tmp/csi/snapshotclass.yaml
cp deploy/example/snapshot/snapshotclass-nfs.yaml /tmp/csi/snapshotclass.yaml
make e2e-bootstrap
make install-nfs-server
}
Expand Down