<h3>Take this scenario:</h3>
<p><a href="https://i.stack.imgur.com/wSqHg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wSqHg.png" alt="enter image description here" /></a></p>
<p>I want to delete every <strong>running</strong> pod <strong>automatically</strong> using the <strong>Commandline</strong> without having to type <code>kubectl delete pod &lt;pod_name&gt; -n &lt;namespace&gt;</code> for each pod.</p>

Jay Shukla
<p>You can use <code>awk</code> to filter pod names based on their <code>STATUS==RUNNING</code>. Below code will delete all(in Running state) the pods from <code>$NAMESPACE</code> namespace.</p>
<pre><code> kubectl  get pod -n $NAMESPACE|awk '$3==&quot;Running&quot;{print $1}'
</code></pre>
<p>Example:</p>
<pre><code>for pod in $(kubectl  get pod -n $NAMESPACE |awk '$3==&quot;Running&quot;{print $1}'); do
    kubectl delete pod -n $NAMESPACE $pod
done
</code></pre>
<p><strong>OR</strong></p>
<p>You may use <code>jsonpath</code>,</p>
<pre><code>NAMESPACE=mynamespace
for pod in $(kubectl  get pod -n $NAMESPACE -o jsonpath='{.items[?(@.status.phase==&quot;Running&quot;)].metadata.name}{&quot;\n&quot;}'); do
    kubectl delete pod -n $NAMESPACE &quot;$pod&quot;
done
</code></pre>
<p>NOTE: Above code will cause deletion of all the pods in <code>$NAMESPACE</code> variable.</p>
<p><strong>Example:</strong></p>
<pre><code>kubectl get pod -n mynamespace
NAME        READY   STATUS      RESTARTS   AGE
foo-mh6j7   0/1     Completed   0          5d3h
nginx       1/1     Running     2          7d10h
mongo       2/2     Running     12         57d
busybox     1/1     Running     187        61d
</code></pre>
<p><code>jsonpath</code> query to print all pods in <code>Running</code> state:</p>
<pre><code>kubectl  get pod -n mynamespace -o jsonpath='{.items[?(@.status.phase==&quot;Running&quot;)].metadata.name}{&quot;\n&quot;}'
nginx mongo busybox
</code></pre>
<p>Although, you have not asked for <code>ready</code> state, but following query can be used to <strong>list pods in ready state</strong>.</p>
<pre><code>kubectl  get pod -n mynamespace -o jsonpath='{range .items[*]}{.status.containerStatuses[*].ready.true}{.metadata.name}{ &quot;\n&quot;}{end}'
foo-mh6j7
nginx
mongo
busybox
</code></pre>
<p>Similarly, this can be done via <code>grep</code>:</p>
<pre><code>kubectl get pod -n $NAMESPACE |grep -P '\s+([1-9]+)\/\1\s+'
</code></pre>
<p><strong>NOTE:</strong> Either of the solution will not prevent <code>pods</code> from getting respawned <strong>if</strong> they are created via <code>replicaset</code> or <code>deployment</code>  or <code>statefulset</code> etc. This means, they will get deleted and respawned.</p>
