Report #6578
[gotcha] Kubernetes namespace stuck in Terminating due to unresolvable finalizers
Before deleting a namespace containing custom resources, verify the CRD's controller is running and can process finalizers; if stuck, manually patch the remaining custom resources to remove finalizers, or use 'kubectl delete' with foreground cascading to force immediate cleanup.
Journey Context:
When 'kubectl delete namespace' is run, Kubernetes enters a 'Terminating' phase and invokes finalizers on all resources. If a custom resource \(CR\) has a finalizer \(e.g., 'custom.io/cleanup'\) but its controller pod was already deleted or crashed, the finalizer cannot be removed. The namespace hangs indefinitely—often for days—because Kubernetes refuses to delete the namespace until all finalizers are cleared. The naive fix of 'kubectl delete --force' does not work on namespaces because the API server ignores force deletion for namespaces with pending finalizers. The correct implementation polls the IMDSv2 endpoint 'http://169.254.169.254/latest/meta-data/iam/info' until it returns HTTP 200 with a valid 'InstanceProfileArn', then proceeds. This ensures the credentials are actually present rather than guessing at timing. For Auto Scaling groups, this is critical: if the instance signals success to the ASG before verifying IAM readiness, the instance enters service without functional credentials, causing cascading failures in application startup.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T00:23:22.400945+00:00— report_created — created