Experiment on Persistent Volume Access Mode
This page mainly does some experiments on changing the access mode if PV or PVC is in use. The testing environment is on VMware TKG - Project Pacific.
If Dynamic provisioning
Create PVC and Pod
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: daniel-pvc
annotations:
volume.beta.kubernetes.io/storage-class: gcstorage
spec:
accessModes:
- ReadOnlyMany
resources:
requests:
storage: 1Gi
storageClassName: gcstorageapiVersion: v1
kind: Pod
metadata:
name: daniel-pod
spec:
restartPolicy: Never
containers:
- name: hello
image: "wcp-docker-ci.artifactory.eng.vmware.com/vmware/photon:1.0"
# The script continously writes some text into the mounted persistent volume. This will ensure the pod is running and the persistent volume is accessible.
command: ["/bin/sh", "-c", "echo 'hello' > /data/persistent/index.html && chmod o+rX /data /data/persistent/index.html && while true ; do sleep 2 ; done"]
volumeMounts:
- name: gc-persistent-storage
mountPath: /data/persistent
volumes:
- name: gc-persistent-storage
persistentVolumeClaim:
claimName: daniel-pvcUsing kubectl apply to create PVC and Pod.
After the creation, you should be able to see that pod is running, PVC is bound.
Modify the access mode under PVC
Modify the access mode under PVC to ReadOnlyMany
Modify the access mode under PV(which is dynamically created)
Modify the access mode under PV to ReadOnlyMany
Strange thing happens under the PVC spec, that spec and status are inconsistent:
However, CLI get returns the correct value:
After changing the access mode to ReadOnlyMany:
The Pod still can write data to the mounted volume
Conclusion:
After changing the access mode under PV to
ReadOnlyMany, the Pod runs fine and the volume is still writableIf delete the Pod and redeploy, the Pod could not be up. That is because VsphereVolume does not support
ReadOnlyManyat this moment. Details
If static provisioning
Create PV, PVC and Pod
Modify the access mode under PVC
Modify the access mode under PV (Statically created)
Modify the access mode to ReadOnlyMany
However, the same inconsistency between spec and status happens as Dynamic Provisioning
And Pod can still write data into the persistent volume after changing the access mode.
Conclusion:
The same conclusion as Dynamic provisinoing scenario
Last updated
Was this helpful?