I am new to k8s. I would like to test the deletionGracePeriodSeconds feature. Documentation says :
deletionGracePeriodSeconds (integer) : Number of seconds allowed for this object to gracefully terminate before it will be removed from the system. Only set when deletionTimestamp is also set.
I guess that if the pod terminates nicely, the feature does not apply.
So, How can I make the pod "reject" deletion in order to see how this feature works? Does it work for deletion by command :
kubectl delete pod mypod
or only with scheduled deletion with "deletionTimestamp"
Here is how I tried to do it (via the trap command) but it does not seem to work :
apiVersion: v1
kind: Pod
metadata:
deletionGracePeriodSeconds: 10
deletionTimestamp: 2020-08-05T14:40:00Z
name: mypod
spec:
containers:
- name: mycontainer
image: nginx
command: ["/bin/sh", "-c"]
args:
- trap "" 2 3 15 20 | sleep 600
Thanks in advance Abdelghani
I assume you are asking about terminationGracePeriodSeconds
, please correct me if I'm mistaken and I'll edit accrodingly.
The terminationGracePeriodSeconds
is the time between Kubernetes sends the SIGTERM
signal to the pod main process (PID 1
) until it sends the SIGKILL
signal, which abruptly kills the process (and subsequently, the pod itself).
SIGTERM
signal is meant to be interpreted by the process, and it should start a "Graceful Shutdown" - stop receiving new tasks and finish the work on existing ones. If the process in your pod needs more than 30 seconds for this procedure (let's say you're running a worker which process each task in 2 minutes), you'd want to extend the terminationGracePeriodSeconds
accordingly.
So you can't make the pod "reject" the deletion, but your process can either ignore the SIGTERM
signal, and then after the period configured in terminationGracePeriodSeconds
it'll be killed abruptly, or it may be that your process needs more time to gracefully shutdown (and in that case, you'd want to increase `