How to Create a Read-Only NVMesh Volume & Populate it with Data
This example describes how to create an NVMesh volume for use as a ReadOnlyMany Persistent Volume.
We will go over creating a Volume, populating it with data and then turn it into a ReadOnlyMany Volume.
Create a Storage Class with reclaimPolicy: Retain.
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: nvmesh-concatenated-retained
provisioner: nvmesh-csi.excelero.com
parameters:
# set here the desired VPG
vpg: DEFAULT_CONCATENATED_VPG
# set reclaimPolicy to retain so that the PV will not be deleted when it's PVC is deleted
reclaimPolicy: Retain
allowVolumeExpansion: true
volumeBindingMode: Immediate
Create a PVC for populating the volume with data.
This will create a new volume with accessMode
ReadWriteOnce
so we can write data into the volume.
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: claim-populate-vol-with-data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: nvmesh-concatenated-retained
volumeMode: Filesystem
Create a pod to write the data to the volume.
Example: This pod will create a file with data.
apiVersion: v1
kind: Pod
metadata:
name: populate-vol-with-data
spec:
restartPolicy: OnFailure
containers:
- name: write-to-volume
image: centos:7
command: ["/bin/bash", "-c", "echo some-data > /data/data.txt"]
volumeMounts:
- name: data-volume
mountPath: /data/
volumes:
- name: data-volume
persistentVolumeClaim:
claimName: claim-populate-vol-with-data
kubectl delete pod populate-vol-with-data
Delete the PVC.
As we used the storage-class with reclaimPolicy: retain, the PV will not be deleted by this action.
kubectl delete pvc claim-populate-vol-with-data
Edit the PersistentVolume Object.
Run this to find the PV created by the Claim:
kubectl get pv -o=custom-columns=NAME:.metadata.name,PVC:.spec.claimRef.name | grep claim-populate-vol-with-data
Edit the PV object by running:
kubectl edit pv <pv name>
Perform the following changes:
kind: PersistentVolume
apiVersion: v1
metadata:
name: pvc-f89b81c9-1c23-40c0-b3a7-eb70525c25ea
spec:
capacity:
storage: 1Gi
csi:
...
accessModes:
# change ReadWriteOnce to ReadOnlyMany
# - ReadWriteOnce
- ReadOnlyMany
# Remove claimRef so that the PV can be bounded again to a new PVC
#claimRef:
# ...
persistentVolumeReclaimPolicy: Retain
storageClassName: nvmesh-concatenated-retained
volumeMode: Filesystem
Create a PVC with ReadOnlyMany.
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: claim-rom
spec:
accessModes:
- ReadOnlyMany
resources:
requests:
storage: 1Gi
storageClassName: nvmesh-concatenated-retained
volumeMode: Filesystem
Create a pod to read the data.
Example Pod:
This pod will read the data.txt
file and then try to delete the file printing the exit code (reading should succeed and deletion should fail).
apiVersion: v1
kind: Pod
metadata:
name: read-data
spec:
restartPolicy: OnFailure
containers:
- name: read-data
image: centos:7
cmd: ["/bin/bash", "-c" ,"cat /data/data.txt ; rm /data/data.txt; echo exit_code=$?"]
volumeMounts:
- name: data-volume
mountPath: /data/
volumes:
- name: data-volume
persistentVolumeClaim:
claimName: claim-rom
Post your comment on this topic.