🎉 DevOps Interview Prep Bundle is live — 1000+ Q&A across 20 topicsGet it →
All Fixes
Today I Fixed

Kubernetes Namespace Stuck in Terminating for 2 Hours

kubectlJun 3, 202612 minutes to fixkubernetestroubleshooting

The Problem

Deleted a namespace that had ArgoCD applications in it. Namespace got stuck in Terminating for over 2 hours. kubectl delete namespace just hung.

What Happened

ArgoCD adds finalizers to namespaces it manages (resources-finalizer.argocd.argoproj.io). After I deleted the ArgoCD application controller, the finalizer was still on the namespace but nothing was there to process it. Kubernetes couldn't complete deletion.

bash
kubectl get namespace my-namespace -o json | jq '.metadata.finalizers'
# ["resources-finalizer.argocd.argoproj.io"]

The Fix

bash
# 1. Export namespace JSON
kubectl get namespace my-namespace -o json > /tmp/ns.json
 
# 2. Remove the finalizer
cat /tmp/ns.json | jq 'del(.metadata.finalizers)' > /tmp/ns-clean.json
 
# 3. Force-finalize via API (proxy needed to bypass auth)
kubectl proxy &
curl -s -X PUT http://127.0.0.1:8001/api/v1/namespaces/my-namespace/finalize \
  -H "Content-Type: application/json" \
  --data-binary @/tmp/ns-clean.json
 
# Kill proxy
kill %1

Namespace deleted within 5 seconds.

Root Cause

Always delete ArgoCD Application resources before deleting their namespace. The finalizer ensures ArgoCD cleans up cloud resources (load balancers, etc.) on deletion. If ArgoCD is already gone, the finalizer hangs forever.