Kubernetes - mount read only share as writable

8/1/2018

I am using this config to mount drive that is read-only to docker image:

volumes:
  - name: drive-c
    hostPath:
      path: /media/sf_C_DRIVE
containers:
  ...
    volumeMounts:
    - name: drive-c
      mountPath: /c

When I try to write (mkdir) to this folder (which is virtual-box read only mounted folder) inside docker image, I get:

mkdir: can't create directory 'somedir': Read-only file system

Which is OK since this is read-only filesystem (C_DRIVE on /c type vboxsf (rw,nodev,relatime))

Is it possible to somehow make this folder writable inside docker container? Changes does not need to be propagated to hostPath. I read something about overlayfs, but I'm not sure how to specify this in Kubernetes yaml.

-- Bojan Vukasovic
docker
kubernetes
overlays
readonly
writable

1 Answer

8/2/2018

You can't do this via Kubernetes volume mounts, as they simply work on volumes. What you need to do is create a writable overlay filesystem on your host machine, then map that into Kubernetes with a different path that is writable.

You want to create something like /mnt/writable_sf_C_drive by mounting your /media/sf_C_DRIVE with an overlay on top of it, then your volume mount in Kubernetes would mount /mnt/writable_sf_C_DRIVE.

There are some instructions here

-- Marcin Romaszewicz
Source: StackOverflow