kubernetes mount a directory readonly in all pod replicas

9/4/2018

What is the best way to mount an external directory in a pod such that:

  1. the pod access to the directory is readonly
  2. whole directory tree is accessible in the pod
  3. any change to the directory contents or creation of new files and directories in this directory is reflected to the pod instantly
  4. all replicas of the pod see the same directory tree

Apparently any solution with ConfigMaps does not satisfy conditions 2 and 3.

-- Nimsa
configmap
kubernetes
persistent-volumes

1 Answer

9/7/2018

Using configMap-s one can achieve all requirements (1) thru (4) except for part of (3) - changes to existing files content (by changing their configMap-s) will be reflected in the pods (almost) instantly but new files or directories won't.

The following script - see here - implements the approach.

Notice that:

  • (1) is now the default starting with 1.9.6 - see this for a discussion.
  • Key for (2) is the use of projected volumes.
  • (4) is out-of-the-box feature as documented here, except for when using subPath.
  • Using a single configMap for all files may cause "...ERROR: The ConfigMap "" is invalid: []: Too long: must have at most 1048576 characters".
  • Using a configMap per file also has a size limitation of ~1MB for the file content (it is an etcd limitation).
-- apisim
Source: StackOverflow