Skip to content

Instantly share code, notes, and snippets.

@kjm0001
Forked from superbrothers/kubectl-delete_all
Created January 15, 2023 13:42
Show Gist options
  • Save kjm0001/22e60b7ee5400ff9025863cb7e8b7b32 to your computer and use it in GitHub Desktop.
Save kjm0001/22e60b7ee5400ff9025863cb7e8b7b32 to your computer and use it in GitHub Desktop.
Kubernetes: Delete all objects in the namespace
kubectl delete "$(kubectl api-resources --namespaced=true --verbs=delete -o name | tr "\n" "," | sed -e 's/,$//')" --all
#!/usr/bin/env bash
#
# kubectl-delete_all is a utility to delete all objects in the namespace.
[[ -n "$DEBUG" ]] && set -x
set -eou pipefail
exec kubectl delete "$(kubectl api-resources --namespaced=true --verbs=delete -o name | tr "\n" "," | sed -e 's/,$//')" --all "$@"
@kjm0001
Copy link
Author

kjm0001 commented Jan 15, 2023

This is useful - but making it easy to copy and paste - this uses fake namespace just for testing
You can copy and paste below lines your shell to try it out

wget https://gist.githubusercontent.com/superbrothers/b428cd021e002f355ffd6dd421b75f70/raw/36200fe7db03360c40b6c97c480d91688db7f2a4/kubectl-delete_all
chmod +x kubectl-delete_all
mkdir ~/bin || { echo "This might fail - that's fine"; } 
export PATH="$HOME/bin:$PATH"
mv kubectl-delete_all ~/bin
kubectl delete-all -n fake

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment