# Fix a namespace stuck in Terminating

> A deleted namespace stays Terminating for good. Find the object whose finalizer holds it and release it without breaking anyone else.

Level: Advanced · Topic: Operations · About 8 minutes
Try it in the browser: https://k8wiz.com/playground/fix-a-namespace-stuck-terminating

The playground is a simulated Kubernetes cluster that runs in the browser. kubectl output and errors follow the real ones.

## The situation

The `legacy` namespace was deleted and never goes away: it still shows `Terminating`. Its Pods are gone, but something inside it is still there.

The team that ran the backup operator in `legacy` uninstalled it before deleting the namespace. Other teams still use Backups.

Find what holds the namespace and let it finish.

## Objectives

1. Find what the namespace waits for (`kubectl describe namespace legacy`)
2. Find the object that holds it
3. The legacy namespace is gone
4. The Backup CRD stays installed (Other teams' Backups depend on it)

## Hints

1. The namespace's conditions name what's left: `NamespaceContentRemaining` lists resource types, `NamespaceFinalizersRemaining` lists finalizers.
2. `kubectl get backups -n legacy -o yaml` shows `metadata.finalizers`. A finalizer is a note that a controller must clean something up first. The operator that would remove this one is gone.
3. Remove the finalizer yourself: `kubectl patch backup nightly -n legacy --type=merge -p '{"metadata":{"finalizers":null}}'`
4. Don't delete the CRD to get rid of it: that deletes every team's Backups.

## Solution

```bash
kubectl describe namespace legacy
```
```bash
kubectl get backups -n legacy
```
```bash
kubectl patch backup nightly -n legacy --type=merge -p '{"metadata":{"finalizers":null}}'
```
```bash
sleep 3
```

## What it teaches

- A namespace finishes deleting only when everything in it is gone. An object with a finalizer waits for its controller to remove it.
- When the controller is gone, nobody removes the finalizer. Removing it by hand skips the cleanup it stood for, so check what it was meant to do (here, deleting snapshots) and do that first if it matters.
- The namespace's conditions tell you which resource types and finalizers are left, so you don't have to search every API.
- Uninstall an operator after deleting the objects it manages, not before.
