2
votes

I want to reduce the number of my pods with full control over the pod that should be shut down. Right now I reduce the number of pods and Kubernetes sends a SIGTERM and after 30 Secounds the pod will be deleted.

I want to know when I listen to the SIGTERM in my pod and exit like this:

if SIGTERM send
  exit(0)

What will Kubernetes do:

  • Restart the pod and kill it after 30 secounds because of the sigterm
  • Ignore the sigterm, because the pod was shut down by itself
  • Throw an error, because it tries to delete a pod that is already deleted
1

1 Answers

0
votes

Kubernetes will delete the pod immediately after the service stops, since the service in your pod has exited normally and as expected.

Catching SIGTERM and shutting down your service is the recommended approach.

You can add your cleanup to your code between if SIGTERM send and exit(0).

if SIGTERM send
  cleanup()
  exit(0)