It is not possible to end the process with PID 1 from preStop shell script so you need to add some logic to the app to terminate itself. Only setup terminationGracePeriodSeconds or together with preStop hook? How to know a Pod's own IP address from inside a container in the Pod? As per #55807 (comment), step-4 of termination lifecycle is justifying above Scenario-2 expressing preStop runs as non-blocking wrt. I used a preStop hook with a bash command to echo a message (just to see if it works !!). One CronJob object is like one line of a crontab (cron table) file. Kubernetes sends the postStart event immediately after a Container is started, and it sends the preStop event immediately before the Container is terminated. Kubernetes PostStartPreStop PostStart. Caution: All CronJob schedule: times are based on the timezone of the kube-controller-manager. @acid_fuji Version is 1.16. One way to address this issue is to trick Kubernetes into keeping your pods alive using a preStop hook, but this seemed too hacky. FEATURE STATE: Kubernetes v1.21 [stable] A CronJob creates Jobs on a repeating schedule. If your app finishes shutting down and exits before the terminationGracePeriod is done, Kubernetes moves to the next step immediately. 158. lifecycle: preStop: exec: command: ["/bin/sh", "-c", "touch /home/node/app/preStop"] Stop your app running as soon as the condition is met. Guarantee execution of preStop in Kubernetes Job. Kubernetes supports the postStart and preStop events. Now the container is nuked "instantly" (1 minute or less) and job is terminated in the middle of work. How can I keep a container running on Kubernetes? Kubernetes does not wait for the preStop Another option is to use Kubernetes Jobs If your pod usually takes longer than 30 seconds to 49. Related. How to pass image pull secret while using 'kubectl run' command? Used terminationGracePeriodSeconds with a delay to preStop and toggle them to see if the process works. Kubernetes K8s Pod K8s Service Pod Pod SIGTERM Pod 102. When the app exits the pod terminates as well. How to debug ImagePullBackOff? My goal is to let container finish its job during new version of application os deployed via Helm. 168. What have you tried? 305. Kubernetes does not wait for the preStop hook to finish. PreStop Hook. This page shows how to attach handlers to Container lifecycle events. The preStop and postStart handlers exists on the containers. Ex. kubernetes 1.5.2 lifecycle lifecyclelifecycle PostStartPreStop In the create_namespaced_job method there is no parameter that exists to define preStop and postStart handlers. to below quotes.. Its important to note that this happens in parallel to the preStop hook and the SIGTERM signal. It runs a job periodically on a given schedule, written in Cron format.