I have the following python
code:
import time
import os
import signal
from abc import abstractmethod
class Stopper:
stop = False
@staticmethod
def safe_stop(*args):
Stopper.stop = true
signal.signal(signal.SIGINT, Stopper.safe_stop)
signal.signal(signal.SIGTERM, Stopper.safe_stop)
while not Stopper.stop:
print("Running...")
time.sleep(1)
os.system("touch /mnt/pod/sig")
print("Done")
And I create a deployment that contains an image with the above Python code.
When I delete the deployment using kubectl delete -f sig.yaml
my Python code does not create the sig file indication and it's not printing the "Done" message.
At this link: https://cloud.google.com/blog/products/containers-kubernetes/kubernetes-best-practices-terminating-with-grace I see that k8s send SIGINT, SIGTERM signals but nothing happens in my application.
How can I make k8s send the signal to my application? What am I doing wrong?