Currently I am working on a K8S project that requires a log file extractor side car container that works alongside the main container to extract log files from the main container. The sidecar container connects via a java web socket to my machine and I can execute commands to retrieve the log files. The log files are maintained within a shared volume mount which is an emptyDir
That works but I need to prepare for a situation at which the main container crashes. If it does then
a) are both the sidecar container and main container restarted from scratch
b) is just the main container started
And also
c) is the shared volume re initialized as an emptyDir
d) all the existing files kept
If case a) or c) occurs what are the termination signals used to terminate the side car container. I plan to use some sort of shutdown hook to listen to it and execute the commands manually before it terminates.
If a container fails, it is restarted according to its restart policy. Other containers in the same Pod and volumes aren't affected.
As you mention you can want termination hook for that you can use the graceful termination hook.
while for restarts you can use the restart policy and manage it but if you are using the emptyDir
volume and your pod schedule to another node then previous data will not be there.
Otherwise if you are running singe node cluster then no issue for volume.