Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Delete Terminating Kubernetes Namespaces with Powershell
$terminatingNamespaces = kubectl get ns --field-selector=status.phase==Terminating -o jsonpath="{range .items[*]}{}{'\n'}{end}"
foreach ($ns in $terminatingNamespaces) {
Write-Verbose '[FOUND]: Forcefully removing $ns'
$jsonObj = kubectl get namespace $ns -o json | ConvertFrom-Json | foreach-object { $_.spec.finalizers = @(); $_ } |
convertto-json | kubectl replace --raw /api/v1/namespaces/$namespace/finalize -f -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment