Created
May 22, 2018 08:23
-
-
Save gitnik/59cb416d4e1b1589cfe79d50287bd6ab to your computer and use it in GitHub Desktop.
kubectl deletion helper
This file contains 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 | |
set -e | |
kubedl () | |
{ | |
TYPE=$1 | |
NAME=$2 | |
NAMESPACE=$3 | |
if [ -z "$TYPE" ] || [ -z "$NAME" ]; then | |
echo "Usage: kubedl <type> <name/label> <namespace=default>" | |
return | |
fi | |
if [ -z "$NAMESPACE" ]; then | |
NAMESPACE="default" | |
fi | |
if [[ "$NAME" =~ "=" ]]; then | |
OBJECT=$(kubectl get "$TYPE" --no-headers --namespace="$NAMESPACE" --ignore-not-found | grep "$NAME" | awk '{print $1}') | |
else | |
OBJECT=$(kubectl get "$TYPE" --no-headers --namespace="$NAMESPACE" -l "$NAME" --ignore-not-found | awk '{print $1}') | |
fi | |
if [ -z "$OBJECT" ]; then | |
echo "$TYPE not found with name/label $NAME" | |
return | |
fi | |
kubectl delete "$TYPE" "$OBJECT" --namespace="$NAMESPACE" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment