Mount propagation in kubernetes Mount propagation in kubernetes kubernetes kubernetes

Mount propagation in kubernetes


In brief, Mount propagation allows sharing volumes mounted by a Container to other Containers in the same Pod, or even to other Pods on the same node.
Mount propagation of a volume is controlled by mountPropagation field in Container.volumeMounts. Its values are:

  • HostToContainer - one way propagation, from host to container. If youmount anything inside the volume, the Container will see it there.
  • Bidirectional - In addition to propagation from host to container,all volume mounts created by the Container will be propagated back tothe host, so all Containers of all Pods that use the same volume willsee it as well.

Based on documentation the Mount propagation feature is in alpha state for clusters v1.9, and going to be beta on v1.10

I've reproduced your case on kubernetes v1.9.2 and found that it completely ignores MountPropagation configuration parameter. If you try to check current state of the DaemonSet or Deployment, you'll see that this option is missed from the listed yaml configuration

$ kubectl get daemonset --export -o yaml

If you try to run just docker container with mount propagation option you may see it is working as expected:

docker run -d -it -v /tmp/mnt:/tmp/mnt:rshared ubuntu

Comparing docker container configuration with kubernetes pod container in the volume mount section, you may see that the last flag (shared/rshared) is missing in kubernetes container.

And that's why it happens in Google kubernetes clusters and may happen to clusters managed by other providers:

To ensure stability and production quality, normal Kubernetes Engine clusters only enable features that are beta or higher. Alpha features are not enabled on normal clusters because they are not production-ready or upgradeable.

Since Kubernetes Engine automatically upgrades the Kubernetes control plane, enabling alpha features in production could jeopardize the reliability of the cluster if there are breaking changes in a new version.

Alpha level features availability: committed to main kubernetes repo; appears in an official release; feature is disabled by default, but may be enabled by flag (in case you are able to set flags)

Before mount propagation can work properly on some deployments (CoreOS, RedHat/Centos, Ubuntu) mount share must be configured correctly in Docker as shown below.

Edit your Docker’s systemd service file. Set MountFlags as follows:

MountFlags=shared

Or, remove MountFlags=slave if present. Then restart the Docker daemon:

 $ sudo systemctl daemon-reload $ sudo systemctl restart docker