Last active
October 1, 2020 03:12
-
-
Save rberrelleza/934ac6cabfccdd17a57817e3b3a5220c to your computer and use it in GitHub Desktop.
script to clean up a 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
#!/bin/bash | |
set -e | |
namespace=$1 | |
if [ -z "$namespace" ]; then | |
echo missing namespace | |
exit 1 | |
fi | |
if [ "$namespace" = "okteto" ]; then | |
echo $namespace is not allowed | |
exit 1 | |
fi | |
ctx=$(kubectl config current-context) | |
echo purging $ctx/$namespace | |
kubectl get namespace $namespace > /dev/null | |
resources=( deployments statefulsets services jobs cronjobs ingress pvc configmap serviceaccount secret) | |
for r in "${resources[@]}" | |
do | |
echo deleting $r | |
kubectl get $r -n=$namespace -o=go-template='{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}' | xargs -n1 kubectl delete $r -n=$namespace | |
done | |
kubectl delete namespace $namespace |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment