Kubernetes 101 : Pods lifecycle hooks - PreStop -



The preStop hook is used to initiate a shutdown of the pod, when stopping the pod via a SIGTERM signal is not possible.
A SIGTERM is a signal that kubernetes uses to gently shutdown a Pod.
The preStop hook is called before the pod is stopped.

We have two types of hooks:
  • Exec - is used to run a command or a script inside a container.
  • HTTP - is used to send HTTP request inside a container.
Below is an example of a pod with an HTTP preStop hook. It sends an HTTP request to the "end" API endpoint of the pod


We get details of our pod using the below command:


The httpGet packet is sent to the address "http://172.17.0.4:80/end".

Comments

Leave as a comment:

Archive