<p>I have a Job as follows:</p>

<pre><code>apiVersion: batch/v1
kind: Job
metadata:
  name: abcd-ca-installer-root
  namespace: abcd-sbenv-test
spec:
  backoffLimit: 2
  activeDeadlineSeconds: 30
  template:
    metadata:
      name: abcd-ca-installer-root
    spec:
      restartPolicy: Never
      activeDeadlineSeconds: 30
      containers:
      - name: abcd-ca-installer-root
        image: abc-dol-tools:5000/abcd-ca-installer:func-tst
        lifecycle:
         preStop:
          exec:
            command: ["/bin/sh", "/usr/local/yezdi/clean.sh"]
        imagePullPolicy: Always
        env:
...
</code></pre>

<p>basically, I would like for the clean.sh to execute after this job is executed successuly. 
I have configured preStop in the above, But, it doesn't look like its executing the clean.sh
any ideas why? or how can I know if this is even trying to run. I have seen this post but it didn'thelp. <a href="https://stackoverflow.com/questions/46525317/how-to-monitor-executing-of-prestop-command">another related question</a></p>

<p>Other version info I am using is </p>

<pre><code># kubectl version
Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.0", GitCommit:"fc32d2f3698e36b93322a3465f63a14e9f0eaead", GitTreeState:"clean", BuildDate:"2018-03-26T16:55:54Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.0", GitCommit:"fc32d2f3698e36b93322a3465f63a14e9f0eaead", GitTreeState:"clean", BuildDate:"2018-03-26T16:44:10Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}

docker --version
Docker version 17.12.1-ce, build 7390fc6

kubeadm version
kubeadm version: &amp;version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.2", GitCommit:"81753b10df112992bf51bbc2c2f85208aad78335", GitTreeState:"clean", BuildDate:"2018-04-27T09:10:24Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
</code></pre>

sbolla
<p>Each container has its lifecycle. You can manage the termination process with Lifecycle Hooks.</p>

<p>I've looked at configuration you provided. PreStop doesn't work the way you expect it.</p>

<p>The PreStop hook is called immediately before a container is <code>terminated</code> not when a pod is gracefully finishing lifecycle.
It is blocking, meaning it is synchronous, so it must complete before the call to delete the container can be sent. 
No parameters are passed to the handler.</p>

<p>You can use a shell script or call http request at the time when PreStop hook is started.</p>

<p>I find Kubernetes <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod/#termination-of-pods" rel="nofollow noreferrer">Termination of Pods</a> documentation useful for this case.</p>
