Kubernetes: How can I save logs of the pod before termination using PreStop hook?

6/10/2020

I want the pods running in my cluster to save their logs just before termination somewhere, so that I can access these logs later and know the termination reason. <br /> Can this be accomplished using the PreStop hook? If yes, please guide me how to do so. <br /> Any other approaches are also welcomed.

-- Tanishq Gupta
debugging
hook
kubernetes
logging

1 Answer

6/10/2020

Use fluentd or fluent bit to send logs to a log aggregator system such as elastic search(EFK stack) or splunk.

Fluentd can run as daemonset in each node and send logs to EFK/Splunk.

Fluentbit can run as a sidecar and send logs to EFK/Splunk

https://kubernetes.io/docs/concepts/cluster-administration/logging/#basic-logging-in-kubernetes

-- Arghya Sadhu
Source: StackOverflow