I am looking for a way to delete all pods of specific deployments of specific namespaces. In other words, given:
x - list of namespaces
y - list of deployments
for i in x:
  for j in y:
    delete all pods of deployment j in namespace i
I would be happy if someone knows how to do it in bash commands.
Thanks!
I believe something like this will do it:
#!/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
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With