Getting notification on file modification within a container in kubernetes pod

11/1/2019

Purpose: I want to develop a CLI tool that allows file synchronization (when files are modified on either machines) between local machine and a remote machine (container in kubernetes pod).

I wanted to know if there is any way (like event triggered) when someone changes application code by bashing into a running container?

-- test_user
kubernetes

1 Answer

11/4/2019

To create a synced directory with your pod and your local machine you can create a sidecar container with sshd image, mount the same volume to both containers and then use sshfs to mount volume from pod to your machine.

Here you can find example how to create shared volume.

Next you can use kubectl to portforward trafic to sshd container:

kubectl port-forward <POD_NAME> 2222:22

And then use sshfs to mount pod's directory to your machine like this:

sshfs root@localhost:/volume my_local_dir -p 2222

more info on sshfs you can find here

Although, like somebody already mentioned in comments:

Directly editing code in a cluster environment isn't usually a good idea [...]

But if you really need to, this is one way to do it.

Let me know if it helped

-- HelloWorld
Source: StackOverflow