Kubernetes shared persistent volume between pods results in no file events

980 Views Asked by At

I have 2 pods that use the same pvc to mount a pv so that they can share files through the mounted directory. Pod A has a Java Application that watches for new files (using java.nio.file.WatchService) in the mounted directory, but if pod B creates/renames/moves/etc. a file to this directory, it shows up on the volume and in pod A but doesn't fire an according event. When I rename or do anything with the file in pod A it gets recognized directly. The storage system is gluster-fs on a local kubernetes cluster.

1

There are 1 best solutions below

0
Jefski14 On

The reason for this behavior is that the Java WatchService can't ensure that file events are correctly generated when using a volume through a bind mount.

This article goes in great depth to why this is the case: https://blog.arkey.fr/2019/09/13/watchservice-and-bind-mount/

The simplest solution to this problem is to check for new files periodically.