preStop hook inside pod using K8s API

11/1/2019

Is there a way to call a function before the Pod is being terminated? preStop hook examples are based on yaml specs.

I want to use the K8s API, should I just write a SIGTERM handler ? What is the "safe" way to do it ?

-- kgunjikar
kubernetes-apiserver

1 Answer

4/9/2020

Please, checkout finalizers.

They exactly get invoked before getting terminated.

example: https://book.kubebuilder.io/reference/using-finalizers.html?highlight=finalizers#using-finalizers

-- Invictus
Source: StackOverflow