Kubernetes pods on failure perform some action

10/20/2020

I have a requirement of executing a sql query if some pod goes down . I wish to update records in database against the hostname of that pod , How can I possibly achieve this what are ways to do this?

-- pawarchinmay27
kubernetes
kubernetes-pod
monitoring
prometheus

1 Answer

10/20/2020

You can implement a handler in the application code which handles SIGTERM signal and make an entry to the DB. A SIGTERMsignal is sent by kubernetes to the running pod before a SIGKILL is sent after the grace period mentioned by terminationGracePeriodSeconds.

As an alternative and safer approach you can offload this responsibility to another application which periodically polls a health-check endpoint exposed by the other app.The health check endpoint can expose the hostname of the app. When health-check fails make an entry to DB.

-- Arghya Sadhu
Source: StackOverflow