Currently I am troubleshooting an issue that I have with some points and I found that when I run a container with docker run command with the following argument:
-v /var/run:/var/run:rw
When I inspect the container I can see the following:
{
"Type": "bind",
"Source": "/var/run",
"Destination": "/var/run",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"
}
I can't find the way of set "Mode": "rw" inside of the MountPaths / Volume definition of a Pod.
I am using:
volumeMounts:
- mountPath: /var/run
name: var-run-mount
volumes:
- name: var-run-mount
hostPath:
path: /var/runand when I inspect the container, I got this:
{
"Type": "bind",
"Source": "/var/run",
"Destination": "/var/run",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
},
I have tried different combinations and MountPropragation but no one helped to achieve what I am looking for and no one also was able to define that "Mode" attribute.
https://kubernetes.io/docs/concepts/storage/volumes/#hostpath
Does someone know if that is possible to be defined?
Have a look at the Access mode attribute of Persistent Volumes in this Kub Documentation link.
It will define how an external storage environment is accessed.
Thank you very much, I have tried out but it didn't work as expected. I got the same outcome.
I am wondering if there is a better storage plugin to use in this use of cases, according to documentation HostPath sounds the right to me.
However, I found something interesting, when specifying at volumeMounts level the readOnly flag, e.g. :
volumeMounts:
- mountPath: /var/run
name: var-run-mount
readOnly: falseI can see the Mode is set to 'ro'.
{
"Type": "bind",
"Source": "/var/run",
"Destination": "/var/run",
"Mode": "ro",
"RW": true,
"Propagation": "rprivate"
}
However trying out the opposite (readOnly: true) didn't give the opposite result. (Mode: rw)
Check out access modes of kubernetes Persistent Volumes.
You can set accessModes: ReadWriteOnce for the hostPath volume.
NOTE: Unfortunately hostPath volume supports only ReadWriteOnce accessMode, other modes like ReadOnlyMany, ReadWriteMany are not supported, as mentioned here in the table.
You need to:
hostPath PersistentVolume as mentioned here.persistentvolumeclaim as mentioned here.Hope this helps.