Handling SIGTERM

Graceful termination isn't a new idea; it is a common practice in programming. Killing a pod forcibly while it's still working is like suddenly unplugging the power cord of a running computer, which could harm the data. 

The implementation principally includes three steps:

  1. Register a handler to capture termination signals.
  2. Do everything required in the handler, such as freeing resources, writing data to external persistent layers, releasing distribution locks, or closing connections.
  1. Perform a program shutdown. Our previous example demonstrates the idea: closing the controller thread on SIGTERM in the graceful_exit_handler handler. The code can be found here: https://github.com/DevOps-with-Kubernetes/okeydokey/blob/master/app.py.

Due to the fact that Kubernetes can only send signals to the PID 1 process in a container, there are some common pitfalls that could fail the graceful handler in our program.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset