Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete multiple namespaces with label option

I have generated a bunch of namespaces like below and now i want to delete only these name spaces without deleting kube-system namespaces,i tried with grep but no success

kubectl delete namespaces | grep "gatling*" error: resource(s) were provided, but no name, label selector, or --all flag specified

Multiple namespaces

like image 475
mark liberhman Avatar asked Oct 18 '25 13:10

mark liberhman


1 Answers

First get the names of the namespaces you want to delete:

kubectl get namespaces --no-headers=true -o custom-columns=:metadata.name | grep gatling

With -o custom-columns=:metadata.name we output only the names of the services. The output is piped to grep, which filters them by looking for gatling.

Then run the delete command for each line with xargs:

kubectl get namespaces --no-headers=true -o custom-columns=:metadata.name | grep gatling | xargs kubectl delete namespace
like image 63
Dávid Molnár Avatar answered Oct 20 '25 13:10

Dávid Molnár



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!