Back to Terraform

Kubernetes Deep Dive: Finalizers, Persistent Data and Failed Teardown

November 6, 2026 Wasil Zafar 26 min read

Trace finalizer/controller/cloud-resource dependencies through a controlled provider-specific rehearsal

Table of Contents

  1. A Stuck Delete Can Protect External State
  2. Inspect PVC, PV and Storage Reclaim Decisions
  3. Restore the Missing Controller or Access Path First
  4. Rehearse Recovery with Disposable Data
  5. Close the Incident with Cluster and Cloud Inventory

A Stuck Delete Can Protect External State

A destroy that hangs is usually a delete being done correctly, one layer at a time. A pipeline job fails with a timeout, the namespace stays in Terminating, and the storage bill keeps climbing. Nothing in the cluster is corrupt. The API is waiting for a controller to finish a promise it made when the object was created.

Kubernetes deletion is a two-phase handshake, not a removal. The API server stamps the object with a deletion timestamp and leaves it readable; the object disappears only when every finalizer in its list has been removed. Each finalizer names a component that still owes cleanup work on something the API server cannot see.

The design exists because objects are not self-contained. A claim stands for a mounted filesystem, a volume stands for a cloud disk, and a namespace stands for a set of objects that may include custom resources owned by an operator. Deleting the API object first and cleaning up second would orphan the real thing every time a controller was slow or absent.

A grace period is not a finalizer, and the difference explains why waiting never helps. A grace period is a countdown for a process to shut down and it applies to pods; a finalizer is an unbounded condition that no clock can expire. When a teardown hangs for hours, the timeout is already irrelevant, and a longer timeout only postpones the same failure.

The stuck state is therefore evidence, not a bug report. A namespace in Terminating with one remaining finalizer is telling you which link failed. The mistake is to read the hang as "Kubernetes will not let go" and reach straight for the finalizer list, because that list is the only record of what still needs to happen.

Four different operations are called "delete" in this story, and only one of them touches bytes.

LayerWho performs itWhat "delete" means hereWhat proves it happened
Terraform deletethe provider, during applya request to the API plus a waiter; the state entry is dropped only after the API stops returning the objectthe next plan no longer proposes the resource
Kubernetes deletethe API servera deletion timestamp is set and the object stays readable in Terminatingthe object is still listed, with a timestamp
Controller cleanupwhichever component owns the finalizerdetach the volume, delete the disk, release an address, drain a shardthe finalizer disappears from the list
Cloud deletethe CSI driver or cloud controllerthe volume or load balancer is removed in the accountthe resource is absent from cloud inventory

Terraform's delete is the shallowest of the four. The provider sends the request, then polls until the object is gone or the timeout expires. A timeout fails the apply while leaving the object in the cluster and the entry in state, which is why the next plan proposes the same destroy again instead of showing a clean slate.

The Kubernetes delete is the only layer you can inspect while it is stuck. A terminating object remains addressable, so its finalizers, owner references and events are all readable. That is the layer that explains why the wait has not ended; the Terraform error message only reports that it has not.

The cloud delete is the layer nobody watches. A disk can outlive every object that referenced it, and the only witness is the account's own inventory. Figure 1 orders the handshake across all four owners so the point of failure has a name.

A Stuck Delete Can Protect External State
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
sequenceDiagram
    autonumber
    participant TF as Terraform apply
    participant API as API server
    participant OWN as Finalizer owner
    participant CSI as CSI driver
    participant CLOUD as Cloud volume API
    TF->>API: DELETE namespace
    API-->>TF: accepted, object Terminating
    Note over API,OWN: The request returned.
The work did not finish. API->>OWN: start namespace cleanup OWN->>API: delete the remaining PVC API-->>OWN: object stays Terminating,
consumer still mounts it OWN->>API: delete the PV, Delete policy API->>CSI: PV marked for deletion CSI->>CLOUD: DeleteVolume CLOUD-->>CSI: volume removed CSI->>API: remove provisioner finalizer API-->>OWN: PV gone OWN->>API: remove last finalizer API-->>TF: object no longer exists Note over TF,CLOUD: Terraform sees success only after
every promise above is kept.

Each link fails on its own, and the failure looks different from the outside. Terraform reports a timeout for all of them. The cluster shows a terminating object for three of them. Only the cloud inventory shows the fourth. Figure 2 puts the chain in one frame and marks the four cut points.

Four owners in one delete, and what a failure at each link looks like Terraform sends a delete request and waits. The API server sets a deletion timestamp and keeps the object readable. A finalizer owner performs the external cleanup, and the CSI driver calls the cloud volume API. Under every link sits the observation that proves that link is the one that stopped: the state entry survives, the object stays terminating, the finalizer never clears, or the disk outlives the object. One delete, four owners, four different failures Read the failure from the outside in: state, object, finalizer, account. TERRAFORM sends DELETE then waits for absence API SERVER sets deletion timestamp, keeps object FINALIZER OWNER does the external cleanup work CLOUD API deletes the disk or the address CUT ONE state keeps the resource the same destroy returns read the error, not a plan CUT TWO object stays readable with a deletion stamp describe it, do not patch CUT THREE a finalizer never clears its owner is gone name the component first CUT FOUR disk outlives object the bill is the witness inventory the account A teardown is complete only when the last link returned success. A timeout tells you the chain stopped. It never tells you where. Removing the finalizer marks links three and four as done. It does not detach the volume, and it does not delete the disk.

The ordering is the safety property. Because the object survives until cleanup finishes, a crash leaves a record instead of an orphan. A stuck teardown is the cluster holding that record open for you, and the useful response is to read it.

Inspect PVC, PV and Storage Reclaim Decisions

Data ownership is decided before deletion, not during it. Three objects hold three different facts, and only one of them is about the bytes. The claim records who is using the volume, the volume records what happens to the disk when the claim goes, and the class records the policy that was copied at creation.

Read the claim first, because it tells you whether anything is still using the data. A terminating claim with the protection finalizer still present has a consumer that has not been removed, and repeating the delete will not change that. The consumer is usually a pod that cannot be evicted, not a claim that refuses to go.

Read the volume second, because it decides the fate of the disk. The reclaim policy on the PV is the field that matters, and it was fixed when the volume was provisioned. Editing the StorageClass now changes the next volume, never this one.

Read the account third, because it is the only witness for the bytes. A PV can be absent while the cloud disk still exists, and a disk can be absent while a snapshot still holds the data. Neither Kubernetes nor Terraform can answer the question alone.

Read thisIt decidesIt cannot prove
claim's finalizer listwhether a consumer still holds the volumethat the consumer is healthy
volume's reclaim policywhether the disk follows the claimthat the driver can reach the cloud API
volume phase and claim referencewhether the bytes are reachable from a new claimthat the filesystem is intact
cloud volume and snapshot inventorywhether the bytes still exist anywherethat the application can use them

Retain is not recovery, and Delete is not instant. Retain moves the volume to Released and keeps the disk, but the volume still references the old claim, so a replacement claim waits instead of binding. Delete asks the CSI driver to remove the disk, and that request can sit behind an attach that never completes.

The protection finalizers are the ones you should never clear by hand. They exist to stop a delete while something is still mounted, and they remove themselves when that condition ends. Clearing one converts a safety mechanism into a race with the kubelet.

Deletion protection belongs in configuration, not in a runbook. A prevent_destroy lifecycle on a claim turns an accidental destroy into a plan error that someone must consciously remove, and the same guard on the namespace covers the objects it owns. The guard is a pause, not a backup.

The guard has one blind spot worth naming. A claim produced by a StatefulSet template never appears in state, so no lifecycle block on it can exist, and a namespace destroy removes it without ever planning its deletion. Guard the namespace, and guard the workload's retention policy, because the claim itself has nowhere to put a guard.

Two fields explain most stuck claims: the consumer and the policy. If a pod still mounts it, remove the pod. If the policy is Retain, the volume will outlive the claim by design and needs an owner rather than a retry.

Figure 3 follows the claim's decision path and stops at each branch that leaves the disk behind.

Inspect PVC, PV and Storage Reclaim Decisions
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','signalColor':'#5a6e82','noteBkgColor':'#c4873b','noteTextColor':'#132440','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    A["Claim in Terminating"] --> B{"Which finalizer
remains?"} B -->|"pvc-protection"| C["A pod still mounts
the volume"] B -->|"provisioner"| D["PV delete is waiting
on the cloud call"] B -->|"operator domain"| E["External system
not cleaned up"] C --> F["Remove the consumer,
then re-read the claim"] F --> G{"Pod actually gone?"} G -->|"node unreachable"| X1["Pod stuck in Terminating
nothing else can move"] G -->|"yes"| H["Claim deletion completes"] D --> I["Check driver pod,
credentials and attach state"] E --> J["Restore the operator,
then let it finish"] H --> K{"Reclaim policy
on the volume"} K -->|"Delete"| L["Driver removes
the cloud disk"] K -->|"Retain"| M["Volume Released,
disk and bytes remain"] M --> N{"Recover or retire?"} N -->|"recover"| O["New claim bound to
the same volume"] N -->|"retire"| P["Snapshot, verify,
then delete both"] I --> L J --> L classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class A,B,G,K,N primary; class C,D,E,F,I,J secondary; class H,L,O,P ok; class X1 danger; class M warn;

The branch you take determines what evidence you must collect next. A protection finalizer needs a consumer check; a provisioner finalizer needs a driver and cloud check; an operator finalizer needs that operator's own records. Table-driven diagnosis beats guessing at the finalizer string.

Restore the Missing Controller or Access Path First

A finalizer names an owner, so read the name before editing the list. The prefix is a domain: the core protection controllers, the CSI provisioner, or a vendor operator. Each string answers the question "who has to run for this to finish", and none of them answers "is it safe to remove".

The most common cause is a controller that is not running. A namespace whose controller cannot list the resources inside it never leaves Terminating, even when nothing in it has a finalizer. Reinstalling or restarting that controller finishes the job without touching a single object.

Discovery failures look exactly like stuck finalizers. A broken aggregated API service, or a CRD whose conversion webhook no longer answers, can stop the namespace controller from enumerating what remains. The namespace then carries a condition that names the failure, which is a far better clue than the object count.

A webhook can block the delete that would fix it. When a validating webhook fails closed, the objects that must go first cannot be deleted, and the API error names the webhook. Disabling admission to clear a backlog is a decision with a blast radius, so scope it to the one resource and re-enable it in the same change.

The cloud-side cause looks like a Kubernetes hang. If the CSI driver was removed during a cost cleanup, the volume's provisioner finalizer can never clear, because nobody is left to call the cloud API. The fix is to restore the driver, not to remove the finalizer that depends on it.

Permissions fail more quietly than crashes. A controller whose service account still exists but whose role binding was removed keeps running and keeps failing. Read its logs for authorization errors before you conclude the object is at fault.

SymptomLikely ownerFirst diagnosticDo not
namespace Terminating, nothing lists insidenamespace controllercontroller manager health and namespace conditionspatch the namespace finalizer
claim Terminating, pod also Terminatingkubelet and nodenode status and pod eventsdelete the claim again
volume stuck deletingCSI provisionerdriver pod logs and cloud API errorsclear the provisioner finalizer
custom resource never goesoperatoroperator deployment, CRDs, webhookdelete the CRD to force it
delete rejected with a webhook nameadmissionwebhook configuration and failure policydisable admission cluster-wide

Restoring is usually cheaper than adopting. Reinstalling a driver or controller is idempotent, it finishes the cleanup the finalizer was waiting for, and it leaves a log that proves the work happened. Manual removal leaves a gap in the record that no later audit can fill.

Blind removal fails in the direction that costs the most. Clearing a claim's protection while a node still writes to the volume lets the filesystem disappear under a running process. Clearing a volume's finalizer while the disk is still attached leaves storage that no object accounts for, and neither failure announces itself at the moment of the edit.

If the owner is permanently retired, removal becomes a decision with a signature. Confirm the external resource is gone or accepted as lost, remove the finalizer through the API, and record who decided and on what evidence. That is a different act from clearing a list to make a pipeline green.

For a namespace, Terraform cannot do this at all. The namespace resource exposes metadata and a couple of settings, not the finalizer list, so the last step is an API-level operation outside the provider. That is a boundary worth knowing before an incident rather than during one.

Figure 4 separates what configuration can change from what only the cluster or the account can change, and puts the removal decision behind an evidence gate.

Three scopes of repair and one gate before removing a finalizer The Terraform scope can change configuration, lifecycle guards and state, but it cannot clear a namespace finalizer. The cluster scope can restore controllers, admission and RBAC. The cloud scope can confirm whether a disk still exists. All three feed one question: is the external resource gone. If it is not, the correct action is to restore the owner and retry. If it is, removal is a recorded manual decision. A footer warns that removing a finalizer without the gate is a claim, not a cleanup. Where the repair can happen, and where the decision must Most stuck teardowns are fixed in the middle column without touching a finalizer. TERRAFORM SCOPE change configuration add a destroy guard refresh or remove state Cannot clear a namespace finalizer. Not in the schema. CLUSTER SCOPE restart the controller repair discovery or a webhook restore a driver or RBAC This is where the finalizer's owner is supposed to run. CLOUD SCOPE list volumes and snapshots check attach state confirm the bytes still exist The only witness that the external resource is gone. GATE: is the external resource gone? answered from inventory, not from the timeout NO: RESTORE THE OWNER reinstall, retry, let the finalizer clear this is the path that keeps the evidence YES: RECORDED REMOVAL name the person, the evidence, and what was accepted as lost Removing a finalizer without the gate records a cleanup that never happened.

The middle column fixes more incidents than the right one. A restart, a reinstalled driver or a repaired role binding is reversible and self-documenting. A finalizer edit is neither, which is why it belongs last.

Rehearse Recovery with Disposable Data

Recovery starts with a read, not a restore. Before anything is allowed to delete, prove the bytes are still where you think they are: clone the disk, mount a copy read-only, and compare a checksum with a value you recorded earlier. If that read fails, you are in a backup incident, not a teardown incident.

Two paths bring data back, and they prove different things. Adopting the existing disk into a new volume proves the original bytes survived; restoring a snapshot proves the backup pipeline works. Rehearse both, because the first fails when the volume record is lost and the second fails when the snapshot was never application-consistent.

Adoption is a handful of fields with exactly one dangerous one. A static volume names the driver, the filesystem type, a matching access mode and capacity, and the provider's handle for the existing disk. All but the handle are recoverable from documentation; the handle is only recoverable from the cloud, and a wrong one silently creates a new empty volume.

Snapshot restore needs the controller, not just the custom resource definitions. Installing the snapshot API without its controller produces objects that are accepted and never become ready. That failure is identical to a slow snapshot, so check the controller before you wait longer.

A drill is only a drill if the namespace is disposable. Same class, same reclaim policy, same controller versions, and a dataset you can afford to lose. A rehearsal in the production namespace is a change with an audience.

Figure 5 shows the order: prove the bytes, choose a recovery path, then prove the end state.

Prove the bytes, choose one of two recovery paths, then prove the end state The left column lists the evidence to collect before any deletion: a ready snapshot, a clone that mounts, and a checksum that matches. The middle column offers two paths, adopting the original disk through a static volume, or restoring a snapshot into a new claim. The right column lists the end state: a bound claim, a verified checksum, an empty orphan inventory. A crimson footer warns that deleting the disk first removes the only copy the other steps depend on. Read, recover, then prove it The order matters more than the tool you use for each step. 1. PROVE THE BYTES snapshot reports ready before you need it a clone mounts in a scratch namespace checksum matches the recorded value No deletion yet. No finalizer edited yet. 2. PICK ONE PATH ADOPT THE SAME DISK static volume, original handle from the account proves the bytes survived RESTORE A SNAPSHOT new claim, new volume proves the backup works carries no old metadata Adoption fails without the handle. Restore fails without the controller. 3. PROVE THE END claim Bound, pod running checksum verified in place no Released volumes left account inventory is clean Deleting the disk first removes the only copy every later step depends on. A teardown that is finished before the data is proven is not a recovery, it is a delay. The rehearsal exists so the proof happens before the pressure does.

Verification after the fix is part of the fix. Watch the finalizer list shrink one entry at a time, confirm each controller's own record, and re-read the claim's phase. A namespace that disappears while a volume is still Released has moved the incident, not closed it.

A recovered claim and a recovered application are two different results. The claim proves the platform can mount the bytes; only an application read proves the data is usable. Do both before the rehearsal is counted as passed.

The namespace is the cheapest proof that the incident is finished. An absent namespace means every namespaced object is gone, including the ones no root ever managed. Pair it with an empty volume list, because the namespace boundary stops at the API server and never reaches the account.

Close the Incident with Cluster and Cloud Inventory

Closure is an inventory question, and it needs four answers. Which namespaces exist, which volumes sit outside any claim, which disks exist in the account, and what Terraform still believes it manages. A blank namespace list with a full disk inventory is not a closed incident.

Write the manual steps down while they are still fresh. Who removed a finalizer, on what evidence, and what was accepted as lost. That record is the difference between a controlled intervention and a habit.

A clean plan is necessary and not sufficient. It proves the provider agrees with the cluster about the objects it manages; it says nothing about controller-created volumes, retained disks or objects owned by another root.

The lab below rehearses the whole path on disposable data, including a deliberate finalizer hang.

Lab

Close the Incident with Cluster and Cloud Inventory

Execution status: design-only. These steps were written for Terraform 1.17.1 with hashicorp/kubernetes 3.5.0 and were not run against a live cluster for this article. Use a disposable cluster, a disposable namespace and a dataset you can afford to lose.

Prerequisites. A cluster where you may create a namespace, a StorageClass, a claim and a workload, plus a CSI driver whose volumes you can list in the cloud console. A snapshot controller and its CRDs if you want to rehearse the second recovery path. Record the Terraform version, the provider version, the kubeconfig context and the server version beside the plan.

  1. Snapshot the starting inventory: namespaces, volumes, claims and the Terraform state list. This is the baseline the closing inventory is compared against.
  2. Create a namespace, a StorageClass with Retain, a claim and a pod that mounts it. Write a small file, record its checksum, and confirm the claim is Bound and the volume's policy is Retain.
  3. Create a stand-in for an operator-owned object: a ConfigMap that carries a finalizer in a lab-owned domain, then confirm a plain delete leaves it present with a deletion timestamp. This reproduces the hang without uninstalling a real controller.
  4. Run the destroy for the namespace resource and expect the apply to time out while the namespace stays in Terminating. Do not retry and do not force anything.
  5. Read the namespace conditions, then list every namespaced kind in the namespace to find what remains. Read the claim's finalizer list and the ConfigMap's, and write down the owner each one names.
  6. Remove the first cause without editing anything: scale the writer to zero, confirm the pod is gone, then watch the claim's protection finalizer clear on its own. Record the delay between the pod leaving and the claim deleting.
  7. With only the lab finalizer left, confirm that nothing outside the cluster depends on that object, then remove the finalizer through the API and watch the namespace finish. Record who removed it and what evidence justified it.
  8. Rehearse recovery on the retained volume: clear its claim reference, bind a new claim to it in a fresh namespace, mount it read-only and compare the checksum with step 2.
  9. Repeat the read through a snapshot restore into a differently named claim, then close with the four inventories: namespaces, volumes, disks and the state list.
EvidenceSourceExpectedWhat it rules out
Namespace still present with a timestampclusterTerminating, not deleteda completed destroy
Condition on the namespaceclustera named failure, not a blank statusan unexplained hang
Claim finalizer listclusteran owner per entrya finalizer with no controller
Protection finalizer after the pod leftclustercleared with no manual editforce-deletion as the fix
Removal of the lab finalizercluster and runbookrecorded, with the evidencea habit of clearing lists
Checksum after adoptionapplication readmatches the baselinea new empty volume
Post-teardown inventorycluster and accountnothing unowneda leaked disk

Expected observation. The destroy times out with the namespace terminating, the claim protected by its consumer and the stand-in object held by its finalizer. Scaling the writer to zero clears the protection finalizer without any manual edit, the recorded removal finishes the namespace, and the retained volume survives as a Released object until it is bound to a new claim. The checksum from the adopted volume and from the restored snapshot both match the baseline, and the closing inventory is empty in the namespace, empty in state, and empty in the account.

Failure checks. A namespace that stays terminating after its contents are gone points at the controller or at discovery, not at a finalizer. A claim whose protection finalizer survives a deleted pod points at a node that never confirmed the pod's removal. A volume that will not bind to a new claim still references the old claim's identity. A disk that survives a Delete policy points at a driver that cannot reach the cloud API.

Cost and cleanup. Retained volumes and snapshots bill until deleted, and a leaked disk can outlive the cluster. Delete the recovered claim, remove the snapshot, delete any remaining volume in the account, then destroy the namespace and confirm all four inventories are empty.

References (checked 6 November 2026): finalizers, namespace deletion, persistent volumes, volume snapshots, and the provider's claim, volume and namespace references.