<p>Team,
I need to delete 10s of pods on k8s cluster that has error. 
I am getting them as below:</p>

<pre><code>kubectl get pods --all-namespaces | grep -i -e Evict -e Error | awk -F ' ' '{print $1, $2, $4}'
test-asdfasdf asdfasdf2215251 Error
test-asdfasdf asdfasdf2215252 Error
test-asdfasdf asdfasdf2215253 Error
test-asdfasdf asdfasdf2215254 Error
test-asdfasdf asdfasdf2215255 Error
test-asdfasdf asdfasdf2215256 Error
</code></pre>

<p>manually am deleting them like this:</p>

<pre><code>kubectl delete pod asdfasdf2215251 -n test-asdfasdf
</code></pre>

<p>but can I write a script that just looks for error on any pod and deletes all of them? I am working on script myself but new to this hence getting late.. </p>

<p>Start point:</p>

<pre><code>kubectl get pods --all-namespaces |
grep -i -e Evict -e Error |
awk -F ' ' '{print $1, $2}' |
</code></pre>

<p>will produce a stream of:</p>

<pre><code>test-asdfasdf asdfasdf2215251
test-asdfasdf asdfasdf2215252
test-asdfasdf asdfasdf2215253
test-asdfasdf asdfasdf2215254
test-asdfasdf asdfasdf2215255
test-asdfasdf asdfasdf2215256
</code></pre>

<p>we can go here:</p>

<pre><code>while IFS=' ' read -r arg1 arg2; do
    kubectl delete pod "$arg2" -n "$arg1"
done
</code></pre>

<p>we can go here:</p>

<pre><code>xargs -l1 -- sh -c 'kubectl delete pod "$2" -n "$1"' --
</code></pre>

<p>or use <code>parallel</code> or any kind of other tools to do that.</p>
