Skip to content

Instantly share code, notes, and snippets.

@rnemeth90
Created April 6, 2022 19:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rnemeth90/19d7de622a5009c1cf908c5d4deb5358 to your computer and use it in GitHub Desktop.
Save rnemeth90/19d7de622a5009c1cf908c5d4deb5358 to your computer and use it in GitHub Desktop.
Delete Terminating Kubernetes Namespaces with Powershell
$terminatingNamespaces = kubectl get ns --field-selector=status.phase==Terminating -o jsonpath="{range .items[*]}{.metadata.name}{'\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