Can a Kubernetes operator watch files in PVC

878 Views Asked by At

Is it possible for a kubernetes operator to watch files in a Persistent Volume Claim(PVC)? I am creating a k8s Golang operator to deploy and manage my application. The application pods will have a mounted volume. I need to be able to stop and start a pod if configuration files are changed on the PVC. Is this possible? I can see in the documentation that I can add a watcher for PVC but not sure if this also watches files updates or changes.

1

There are 1 best solutions below

0
On

As mentioned in the comments, you would need a ReadWriteMany-capable volume provider but then sure. This isn't how most operators work so you'll have to manage the file watch yourself but there's some good low-level inotify bindings available and I think Viper can reload on the fly itself. Combine that with a channel watch in controller-runtime and a background goroutine interfacing with the file watch that injects reconcile events, and you should be all set.

That said, RWX volumes are to be avoided unless absolutely necessary as all existing providers (NFS, CephFS, etc) each come with notable downsides and caveats to be aware of. Also this is not the general model of how operators should work, they should be API-driven. A possibly better approach is instead of a shared RWX volume containing the config, have a controller-like sidecar in each pod that's watching the API and regenerating the config in a pod-shared emptyDir volume. That's basically how most Ingress Controllers work, so you could use those as an example.