Created
March 4, 2019 22:43
-
-
Save jaytaylor/1d0695cbe42f1b818872a732e02205ba to your computer and use it in GitHub Desktop.
Delete all resources from a Kubernetes namespace.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# @author Jay Taylor [jaytaylor.com](https://jaytaylor.com) | |
# | |
# @date 2019-03-04 | |
# | |
# Sometimes Kubernetes seems to get stuck and doesn't | |
# delete the contents of a namespace from my cluster after | |
# `kubectl delete namespace X` has been run. | |
# | |
# This small program lists and deletes each resource from | |
# the specified namespace. | |
# | |
# Also see ctron's "kill-kube-ns", you may need it as a | |
# last step: | |
# | |
# https://github.com/ctron/kill-kube-ns | |
# | |
set -o errexit | |
set -o pipefail | |
set -o nounset | |
if [[ "${DEBUG:-}" =~ ^1|[tT](rue)?|[oO]n?|[yY](es)?$ ]] ; then | |
set -o xtrace | |
fi | |
if [ -z "${1:-}" ] ; then | |
echo 'ERROR: missing required argument: namespace' 1>&2 | |
exit 1 | |
fi | |
ns="$1" | |
kubectl get all -o json --namespace "${ns}" \ | |
| jq -r '.items[] | .kind + "/" + .metadata.name' \ | |
| xargs -n1 -IX kubectl delete X --namespace "${ns}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment