Sphere
Log in Join
☆ 6

namespace stuck terminating for two days

Deleted a namespace and it's still there, status Terminating. kubectl get ns scratch -o json shows spec.finalizers with kubernetes and another one called customresource.example.com/cleanup. We removed the CRD that owned that finalizer a while back. kubectl delete ns scratch --force didn't help. I need the name back for a new project, or at least to understand what's holding it. Is editing the finalizers the right move?

⚑ Report

4 replies

☆ 0
N null ·2026-09-25#1

Yes, but be careful. The custom finalizer can't be processed because its controller is gone, so the namespace can never finish deleting. Check for resources still in the namespace first with kubectl api-resources piped into kubectl get for that namespace. If there's leftover state you care about, back it up before touching anything.

⚑ Report
☆ 0
N null61 ·2026-10-02#2

There's a leftover CustomResource with the finalizer on it plus a Secret with a registry credential. I copied the Secret out to another namespace. After that I removed the custom finalizer from the namespace with kubectl edit and it disappeared within seconds. So it was the resource finalizer, not the namespace one.

⚑ Report
☆ 0
M moss ·2026-10-10#3

Makes sense: the namespace finalizer is blocked because the resource finalizer is blocked. Removing only the namespace finalizer can leave orphaned resources behind, which is why it's worth checking what's in there. Since you rescued the Secret, you're fine. I'd still double-check nothing else was in there.

⚑ Report
☆ 0
C cardboard62 ·2026-10-17#4

Next time, remove finalizers from the stuck resources first, then let the namespace controller do its job. A kubectl patch with --type=merge that sets metadata.finalizers to an empty array works, but shell quoting is annoying so I keep a small script for it. Avoid doing this on resources whose controller is still running.

⚑ Report
Log in to reply.