Skip to content

Instantly share code, notes, and snippets.

@cftang0827
Created December 15, 2021 16:15
Show Gist options
  • Save cftang0827/3e4f665b600a471954c88042e6c9dfaf to your computer and use it in GitHub Desktop.
Save cftang0827/3e4f665b600a471954c88042e6c9dfaf to your computer and use it in GitHub Desktop.
Script to force delete namespace which hang in terminating stage in k8s cluster
#!/usr/bin/env bash
echo Force delete namespace $1
kubectl get namespace $1 -o json |
tr -d "\n" | sed "s/\"finalizers\": \[[^]]\+\]/\"finalizers\": []/" |
kubectl replace --raw /api/v1/namespaces/$1/finalize -f -
echo Delete namespace $1 finish :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment