How to make the Kubernetes pod aware of new file changes?

1/6/2021

Is there a way to make Kubernetes Pods aware of the new file changes ?

Lets say, I have an Kubernetes(K8) pod running with 4 replicas created, also I have an K8 PV created and attached to the external file system where we can modify the files. Lets consider K8 pod is running a tomcat server with an application name test_app which is located in the following directory inside the container tomcat/webapps/test_app/ Inside the test_app directory, i have few sub-directories like below test_app/xml test_app/properties test_app/jsp

All these sub-directories are attached to an volume and it is mounted to an external file system. Anyone who have access to the external file system, will be updating xml / properties / jsp files. When these files are changed in the external file system, it will get reflected inside the sub-directories test_app/xml, test_app/properties, test_app/jsp as well as we have an PV attached. But these changes will not reflected in th web application unless we restart the tomcat server. To restart the tomcat server, we need to restart the pod.

So whenever someone make any changes to the files exist in the external file system, how do i make K8 aware that there is some new changes which require Pods needs to be restarted ? is it even possible in Kubernetes right now ?

-- babs84
docker
kubernetes
kubernetes-pod
persistent-volumes
volume

1 Answer

1/6/2021

If you are referring to file changes meaning changes to your application, the best practice is to bake a container image with your application code, and push a new container image when you need to deploy new code. You can do this by modifying your Kubernetes deployment to point to the latest digest hash.

For instance, in a deployment YAML file:

image: myimage@sha256:digest0

becomes

image: myimage@sha256:digest1

and then kubectl apply would be one way to do it.

You can read more about using container images with Kubernetes here.

-- Alex Watt
Source: StackOverflow