What's Actually Happening

Kubernetes namespace is stuck in Terminating state and cannot be deleted.

The Error You'll See

```bash $ kubectl get namespace myapp

NAME STATUS AGE myapp Terminating 1h ```

Why This Happens

  1. 1.Resource finalizers - Resources have stuck finalizers
  2. 2.APIService pending - API service not cleaned up
  3. 3.Webhook blocking - Admission webhook not responding
  4. 4.Pending resources - Resources not fully deleted

Step 1: Check Namespace Resources

```bash # Get all resources: kubectl api-resources --verbs=list --namespaced -o name | \ xargs -n 1 kubectl get --show-kind --ignore-not-found -n myapp

# Check events: kubectl get events -n myapp ```

Step 2: Remove Finalizers

```bash # Get namespace finalizers: kubectl get namespace myapp -o jsonpath='{.spec.finalizers}'

# Remove finalizers: kubectl patch namespace myapp --type json -p='[{"op": "replace", "path": "/spec/finalizers", "value": []}]'

# Or for resources: kubectl patch resource myresource -n myapp --type json -p='[{"op": "replace", "path": "/metadata/finalizers", "value": []}]' ```

Step 3: Force Delete

```bash # Force delete namespace: kubectl delete namespace myapp --force --grace-period=0

# Or via proxy: kubectl proxy & curl -X PUT localhost:8001/api/v1/namespaces/myapp/finalize -H "Content-Type: application/json" --data-binary @- <<EOF { "kind": "Namespace", "apiVersion": "v1", "metadata": { "name": "myapp" }, "spec": { "finalizers": [] } } EOF ```

Namespace Terminating Checklist

CheckCommandExpected
Finalizersget -o jsonEmpty
Resourcesget allDeleted
Eventsget eventsNo errors

Verify the Fix

bash
kubectl get namespace myapp
# Output: Error from server (NotFound)
  • [Fix Kubernetes Pod Stuck Terminating](/articles/fix-kubernetes-pod-stuck-terminating)
  • [Fix Kubernetes Resource Quota Exceeded](/articles/fix-kubernetes-resource-quota-exceeded)