Skip to content

Instantly share code, notes, and snippets.

@zAbuQasem
Created December 10, 2025 22:53
Show Gist options
  • Select an option

  • Save zAbuQasem/a227741bd0594bd68641ba179e6216e6 to your computer and use it in GitHub Desktop.

Select an option

Save zAbuQasem/a227741bd0594bd68641ba179e6216e6 to your computer and use it in GitHub Desktop.
Shell function that delete a namespace stuck in terminating state.
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