agentleFS
boettiger-labboettiger-lab/agent-skills/k8s-never-force-delete/SKILL.md

k8s-never-force-delete

Skill4 starsChanged 15 days agoBSD-3-ClauseView on GitHub

Kubernetes deletion safety — never force-delete. Consult BEFORE any `kubectl delete`, and especially before reaching for `--force`, `--grace-period=0`, or editing/removing finalizers to make a stuck object go away. Graceful deletion only; diagnose stuck resources instead of forcing them. Triggers on: kubectl delete, --force, --grace-period, stuck Terminating, stuck namespace, remove finalizer, force delete pod/pvc/ns.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    If a pod is stuck because its node is genuinely gone, delete/​drain the Node object (or let the node controller evict) rather than …

    line 50

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Never force-delete in Kubernetes

The rule

Do not use --force, --grace-period=0, or strip finalizers to delete a Kubernetes object. Use a normal graceful kubectl delete and let termination complete. This applies to every resource — pods, jobs, deployments, StatefulSets, PVCs, namespaces.

Specifically, never do (on your own initiative):

  • kubectl delete pod X --force --grace-period=0
  • kubectl delete ... --grace-period=0
  • kubectl patch ns/pvc ... -p '{"metadata":{"finalizers":[]}}' (or --finalize / editing finalizers to null) to clear a "stuck Terminating" object
  • kubectl delete namespace X when it hangs, then force-finalizing it

Why it's dangerous

--force --grace-period=0 deletes the API object without confirming the workload actually stopped. Consequences:

  • StatefulSet / single-writer pods: the replacement pod starts while the old container may still be running → two writers at once (split-brain), data corruption, duplicate external side effects. Force-deleting a StatefulSet pod is explicitly unsafe.
  • PVCs / volumes: force/finalizer-stripping orphans the real backing volume or leaves it attached, and can lose data.
  • Namespaces: clearing finalizers abandons real resources (cloud LBs, disks, external records) that the finalizer existed to clean up — silent leaks and cost.

A "stuck Terminating" object is a symptom, not the problem. Forcing it hides the cause.

Do this instead

  1. kubectl describe the object and look at events, deletionTimestamp, and finalizers.
  2. Find what's blocking termination: a controller/operator, a volume that won't detach, an admission/finalizer webhook that's down, a node that's NotReady, a pod with a stuck preStop hook.
  3. Fix the cause (bring the webhook/controller back, cordon+investigate the node, resolve the volume). Graceful deletion then completes on its own.
  4. If a pod is stuck because its node is genuinely gone, delete/​drain the Node object (or let the node controller evict) rather than force-deleting the pod.

The one exception

Force-delete only with explicit human authorization, on a specifically diagnosed resource where the graceful path is confirmed impossible (e.g. a pod on a permanently-dead node with no StatefulSet single-writer risk). Never as routine, never as a shortcut to "make it go away," never on a StatefulSet pod without confirming the old container is truly dead. State why in the moment.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.