Kubernetes mount volume on existing directory with files inside the container

Unfortunately Kubernetes’ volume system differs from Docker’s, so this is not possible directly.

However, in case of a single file foo.conf you can use:

  • a mountPath ending in this file name and
  • a subPath containing this file name, like this:
    volumeMounts:
    - name: cephfs-0
      mountPath: /opt/myapplication/conf/foo.conf
      subPath: foo.conf

Repeat that for each file. But if you have a lot of them, or if their names can vary, then you have to handle this at runtime or use templating tools. Usually that means mounting it somewhere else and setting up symlinks before your main process starts.

Leave a Comment