How to keep wait pod termination until current processes done in kubernetes?

8/7/2019

We have a pod in kubernetes and it is processing some jobs in there regularly. Some of these jobs take more than 2 or 3 minutes. When deploying this pod, we don't want to kill current processes on this pod. How to keep wait this pod's termination until all processes completed? I read some topics about 'terminationGracePeriodSeconds'. But is there any upper seconds limit about that property or how it works?

-- tembelmuhendis
cluster-computing
containers
kubernetes
pod
terminate

1 Answer

8/7/2019

You can use wait command, which takes multiple resources and waits until the specified condition.

For example, assume you create a job called worker that print the word 'printsth' and pause for 3 seconds ten times.

$ kubectl create ns waitplayground
$ kubectl -n waitplayground \
             create job worker \ 
             --image centos:7 -- \
             sh -c \
             'for i in {1..10} ; do echo printsth ; sleep 3; done'

Kubectl wait command returns something similar to that:

$ kubectl -n waitplayground \
             wait --for=condition=complete --timeout=40s \     
             job/worker
job.batch/worker condition met

I hope it will helps you.

-- muscat
Source: StackOverflow