Created
December 10, 2025 22:53
-
-
Save zAbuQasem/a227741bd0594bd68641ba179e6216e6 to your computer and use it in GitHub Desktop.
Shell function that delete a namespace stuck in terminating state.
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
| k8s_force_delete_ns() { | |
| local ns="$1" | |
| # If no namespace provided, use fzf to pick from terminating namespaces | |
| if [[ -z "$ns" ]]; then | |
| ns="$( | |
| kubectl get ns \ | |
| --field-selector=status.phase=Terminating \ | |
| -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' \ | |
| | fzf --prompt='Terminating namespaces > ' --height=10 --reverse | |
| )" | |
| if [[ -z "$ns" ]]; then | |
| echo "No namespace selected, aborting." >&2 | |
| return 1 | |
| fi | |
| fi | |
| echo "Force deleting namespace: $ns" >&2 | |
| kubectl get namespace "$ns" -o json \ | |
| | jq '.spec.finalizers = []' \ | |
| | kubectl replace --raw "/api/v1/namespaces/${ns}/finalize" -f - | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment