kubectl delete all resources except the kubernetes service

9/17/2018

Is there a variant of kubectl delete all --all command or some other command to delete all resources except the kubernetes service?

-- Nimsa
kubectl
kubernetes

1 Answer

9/17/2018

I don't think there's a built-in command for it, which means you'll have to script your way out of it, something like this (add an if for the namespace you want to spare):

$ for ns in $(kubectl get ns --output=jsonpath={.items[*].metadata.name}); do kubectl delete ns/$ns; done;

Note: deleting a namespace deletes all its resources.

-- Michael Hausenblas
Source: StackOverflow