Merge pull request #557 from umagnus/add_snapshot_doc

doc: add snapshot feature doc
This commit is contained in:
Kubernetes Prow Robot 2023-12-04 03:56:29 +01:00 committed by GitHub
commit 6fad9f1b44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 120 additions and 3 deletions

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
}