<p>I have encountered a problem that does not stop immediately even if I delete pod.</p>

<p>What should be fixed in order to terminate normally?</p>

<h2>manifest file.</h2>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: cmd-example
spec:
  replicas: 1
  selector:
    matchLabels:
      app: cmd-example
  template:
    metadata:
      labels:
        app: cmd-example
    spec:
      terminationGracePeriodSeconds: 30
      containers:
      - name: cmd-container
        image: alpine:3.8
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
        command: ["/bin/sh"]
        args: ["-c", "while true; do exec sleep 100;done"]
</code></pre>

<h2>Reproduction procedure</h2>

<ol>
<li>create deployment.<br>
<code>$ kubectl apply -f deployments.yaml</code></li>
<li>delete deployment.<br>
<code>kubectl delete-f 020-deployments.yaml</code></li>
</ol>

<p><code>kubectl get po -w</code>output is.</p>

<pre><code>cmd-example-5cccf79598-zpvmz   1/1       Running   0         2s
cmd-example-5cccf79598-zpvmz   1/1       Terminating   0         6s
cmd-example-5cccf79598-zpvmz   0/1       Terminating   0         37s
cmd-example-5cccf79598-zpvmz   0/1       Terminating   0         38s
cmd-example-5cccf79598-zpvmz   0/1       Terminating   0         38s
</code></pre>

<p>This should finish faster.<br>
It took about 30 seconds to complete. Perhaps it is due to SIGKILL at the time of terminationGracePeriodSeconds 30s.<br>
<strong>Why is not pod cleanup immediately with SIGTERM?</strong></p>

<p>What should be fixed?</p>

<h2>Environment</h2>

<p>I confirmed it in the following environment.</p>

<ul>
<li>Docker for Mac:18.06.1-ce,Kubernetes :v1.10.3</li>
<li>Docker for Windows:18.06.1-ce,Kubernetes :v1.10.3</li>
<li>Google Kubernete Engine:1.11.2-gke.15</li>
</ul>

<h2>Cause of a problem</h2>

<p>This shell is that it does not stop even if it accepts the signal of SIGTERM.</p>

<h2>Solution</h2>

<p>Using the trap command.</p>

<p><strong>Changed place</strong></p>

<pre><code>    command: ["/bin/sh"]
    args: ["-c", "trap 'exit 0' 15;while true; do exec sleep 100 &amp; wait $!; done"]
</code></pre>

<h2>Result</h2>

<p>after delete, pod was cleaned up as soon!</p>

<pre><code>img-example-d68954677-mwsqp   1/1       Running   0         2s
img-example-d68954677-mwsqp   1/1       Terminating   0         8s
img-example-d68954677-mwsqp   0/1       Terminating   0         10s
img-example-d68954677-mwsqp   0/1       Terminating   0         11s
img-example-d68954677-mwsqp   0/1       Terminating   0         11s
</code></pre>
