1

I have a problem. There is preStop option in manifest file and OOMKilled was happened. pod was restarted but no heapdump is created.

lifecycle: preStop: exec: command: ["/tmp/preStop.sh"]

heapdump works when I manually terminate the pod.

so I wonder if pod is restarted, preStop is not supposed to be executed?

I thought when pod is restarted, first send TermSignal to application and execute preStop and terminate and start pod again. Am I wrong?

Thanks Best Regards.

user2286858
  • 59
  • 1
  • 5

2 Answers2

2

when the pod is restarted, first send TermSignal to the application and execute preStop and terminate and start pod again. Am I wrong?

As per the official documentation

PreStop hooks are not executed asynchronously from the signal to stop the Container; the hook must complete its execution before the TERM signal can be sent.

If a PreStop hook hangs during execution, the Pod's phase will be Terminating and remain there until the Pod is killed after its terminationGracePeriodSeconds expires. This grace period applies to the total time it takes for both the PreStop hook to execute and for the Container to stop normally.

Hope the above information is useful to you.

1

This is a known behavior for OOMKilled pods to not invoke preStop hook.

As explained by Chanpreet08 (GitHub user)

K8 gives SIGTERM signal if it wants to terminate the pod, but in case of OOM, it passes SIGKILL to the pod which instantly kills the main process and finally terminates the pod without waiting for the prestop to execute. So in case of OOM, the prestop won;t execute.

https://github.com/kubernetes/kubernetes/issues/93818

Rakesh Gupta
  • 3,507
  • 3
  • 18
  • 24