We got OOMKilled event on our K8s pods. We want in case of such event to run Native memory analysis command BEFORE the pod is evicted. Is it possible to add such a hook?
Being more specific: we run with -XX:NativeMemoryTracking=summary
JVM flag. We want to run jcmd <pid> VM.native_memory summary.diff
just BEFORE pod eviction to see what causes OOM.
Looks like it is almost impossible to handle.
Based on an answer on Github about a gracefully stop on OMM Kill:
Here is from official documentation:
So, as you understand, you have not much chance to handle it somehow. Here is the large article about the handling of OOM, I will take just a small part here, about memory controller out of memory handling:
The only thing I can offer is getting a data from cAdvisor (here you can get an OOM Killer event) or from Kubernetes API and run your command when you see by metrics that you are very close to out of memory. I am not sure that you will have a time to do something after you will get OOM Killer event.