Obtain warning about resources to be deleted in Kubernetes

When you delete a namespace, all namespaced resources in this namespace will be deleted. There’s no direct way to list all the resources in a namespace (kubectl get all lists only a selected set of resources).

However, you can enumerate all namespaced resource types with:

kubectl get api-resources --namespaced=true

And you can then iterate through these resource types and check if you have any instances of them in your namespace with kubectl get.

For example, the following command lists all resources in the ns-name namespace:

for r in $(kubectl api-resources --namespaced=true --no-headers 2>/dev/null | cut -d ' ' -f 1); do 
  kubectl get "$r" -n ns-name --no-headers -o custom-columns=:.metadata.name | sed "s/^/$r /"
done

And this are all the resources that will be deleted when you delete the ns-name namespace.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top