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
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