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?
You can implement a handler in the application code which handles SIGTERM
signal and make an entry to the DB. A SIGTERM
signal 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.