Fast kubectl mass delete

kubectl delete -A --all

Is very slow, because under the hood it runs 1 delete at a time. (easy to see with -v 8)

A much faster way is to talk to the api directly:

kubectl delete --raw /api/v1/namespaces/foo/pods

That also works with label selectors, for example foo=bar would be:

/api/v1/namespaces/foo/pods?labelSelector=foo%3Dbar

… and deleting everything in foo namespace would be:

/api/v1/pods/namespaces/foo

It does not work without a namespace,
so to delete everything with a given label we have to fetch first and then iterate all namespaces.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s