<p>I am looking for a way to delete all pods of specific deployments of specific namespaces. In other words, given:  </p>

<blockquote>
  <p>x - list of namespaces<br>
  y - list of deployments  </p>
</blockquote>

<pre><code>for i in x:
  for j in y:
    delete all pods of deployment j in namespace i
</code></pre>

<p>I would be happy if someone knows how to do it in bash commands.  </p>

<p>Thanks!</p>

<p>I believe something like this will do it:</p>

<pre><code>#!/bin/bash

NAMESPACES=( n1 n2 n3 )
DEPLOYMENTS=( dep1 dep2 dep3 )

for i in "${NAMESPACES[@]}"
do
  for x in "${DEPLOYMENTS[@]}"
  do
     # Get the pods in the deployment
     PODS=$(kubectl -n $i get pods --no-headers | awk '{print $1}' | grep $x | tr '\n' ' ')
     kubectl -n $i delete pods $PODS
  done
done
</code></pre>
