I have Filebeat running in a sidecar container, alongside my app container, in a Kubernetes pod. They share an attached volume: the app is writing JSON logs and Filebeat is shipping them.
I have a daemonset Filebeat running which ships stdout/stderr already, this is about the app-specific Filebeat logging/shipping, which might go to an app-specific cloud.elastic.co instance, for example.
This works well on the whole, but if the pod is terminated, both containers receive SIGTERM at the same time it seems, and so if app container takes a couple of seconds to shut down, logging some additional output as it does so, it's not picked up and shipped by the Filebeat container.
Is there any way to:
- Configure Filebeat to not exit in response to SIGTERM until there's nothing left to be processed (maybe with timeout?)
- Configure the Filebeat docker image to do so?
- Configure a Kubernetes pod to delay termination of a particular container in a pod
Nr. 3 seems the least favourable, because it always introduces a delay. That one is also maybe off topic, but I figured it might be a use case that's come up here before!