<p>kubernetes cron job which should run every 10mins and should  delete the pods 
which are in "Terminating" state in all the namespaces in the cluster? please 
help me out....am struggling with the bash one liner shell script</p>

<pre><code>  apiVersion: batch/v1
  kind: Job
  metadata:
  name: process-item-$ITEM
  labels:
  jobgroup: jobexample
  spec:
  template:
  metadata:
  name: jobexample
  labels:
    jobgroup: jobexample
spec:
  containers:
  - name: c
    image: busybox
    command: ["sh", "-c", "echo Processing item $ITEM &amp;&amp; sleep 5"]
  restartPolicy: Never
</code></pre>

rohit rocckz
<p>List all terminating pods in all namespace with the format {namespace}.{name}</p>

<pre><code>kubectl get pods --field-selector=status.phase=Terminating --output=jsonpath='{range .items[*]}{.metadata.namespace}{"."}{.metadata.name}{"\n"}{end}' --all-namespaces=true
</code></pre>

<p>Given a pod's name and its namespace, it can be force deleted by</p>

<pre><code>kubectl delete pods &lt;pod&gt; --grace-period=0 --force --ns=&lt;namespace&gt;
</code></pre>

<p>In one line</p>

<pre><code>for i in `kubectl get pods --field-selector=status.phase=Terminating --output=jsonpath='{range .items[*]}{.metadata.namespace}{"."}{.metadata.name}{"\n"}{end}' --all-namespaces=true`; do kubectl delete pods ${i##*.} --grace-period=0 --force --ns=${i%%.*}; done
</code></pre>
