5

I am working with Kubernetes and a pod is composed by different containers.

I need to apply different behaviours when two specific events happen:

  1. a container (for whatever reason) have problems and need to be restarted. This happens when liveness probe fails
  2. a pod is scheduled to be stopped. For example I am rolling out a new version and kubernetes terminates the previous one and spin up the new one

From what I understood in both the cases kubernetes invokes the preStop hook and sends a SIGTERM, so it's impossible for me to understand in which of the two situations I am. Is that right? Am I missing something?

Thanks

Dreams
  • 5,854
  • 9
  • 48
  • 71
Michele Orsi
  • 754
  • 4
  • 17
  • if you pull the Pod status data from the API, you should be able to tell if it's a liveness problem. Or you could just call the liveness probe yourself in your preStop script to see if it answers. – MrE Dec 05 '16 at 16:27
  • 1
    Can you give a bit more info on why you need separate behaviour in each case? In general your pods need to be able to survive being torn down at any time, so can you decouple the "shutdown" behavour and run it as part of your init container in the new deployment? – Symmetric Jun 09 '17 at 22:56
  • Have you got the solutions? – Tariv Feb 19 '21 at 10:56

0 Answers0