Define `Mode: rw` attribute container in Kubernetes MountPath definition

8/31/2019

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/run

and 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?

-- Penguin_HuHu
docker
kubernetes

3 Answers

8/31/2019

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.

-- AYA
Source: StackOverflow

9/2/2019

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: false

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

-- Penguin_HuHu
Source: StackOverflow

8/31/2019

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:

  • First create hostPath PersistentVolume as mentioned here.
  • And then create persistentvolumeclaim as mentioned here.
  • Finally create a Pod referring to that hostPath volume resource as mentioned here.

Hope this helps.

-- mchawre
Source: StackOverflow