Search code examples
kubernetesstoragenfs

How to mount Kubernetes directory as some other directory?


I have a Kubernetes app that I want to copy to another environment. The original app uses container directory /data/X and synchronizes it with NFS server.

I have a following problems:

  • I want to run new app in another environment and must not overwrite NFS storage of the original app
  • I need to create /data/X directory in the container of new app, as the developers rely on this directory inside container - they install software there and create files inside

My question is: Is there any option for me to create directory /data/Y inside container on the environment and let it act as a folder /data/X so the software is installed inside container correctly, files are created and NFS storage of the original app is not overwritten?


Solution

  • Do you just want the /data/X folder to be inside the running container and not on the NFS for this new environment?

    If so you can make sure that /data/X folder is created as part of the image, for example by putting this line in the Dockerfile

    RUN mkdir -p /data/X
    

    In the original environment you mount NFS storage on /data/X. This will behave like mounts do in Linux, i.e that they shadow everything in /data/X on the local file system and you appear to read/write to the NFS share.

    In the new environment you are creating you just skip mounting anything there. The developers can still use /data/X as they usually would, but the content will not be persisted and it will not be possible to share it between containers