DEV Community

Shubham
Shubham

Posted on

4 1 1 1 1

How a Pod is Deleted - Behind the Scenes Breakdown

When we run kubectl delete pod , the confirmation message pops up saying the pod is deleted(if all good)

$ kubectl delete pod platform-pod

pod "platform-pod" deleted
Enter fullscreen mode Exit fullscreen mode

Wondered, what happens behind the scenes?
Before diving into pod deletion behind the scenes, you should know the basics.

SIGTERM: Requests a graceful shutdown, allowing the program to finish tasks and clean up. In Kubernetes, pods get time to exit cleanly.

SIGKILL: Forces an immediate stop, with no cleanup. If a pod doesn't shut down in time after SIGTERM, Kubernetes sends SIGKILL to terminate it.

In short,

  • SIGTERM allows for cleanup.
  • SIGKILL stops everything instantly.

Pod Deletion - Behind the Scenes:

Image description

kubectl delete pod: Triggers the API Server to update ETCD with deletionTimestamp and deletionGracePeriodSeconds, marking the pod as Terminating.

API Server → Kubelet: Notifies the Kubelet of the pod’s termination.

Endpoint Controller: Removes the pod from active service endpoints, stopping any traffic from reaching the pod.

PreStop Hook (if configured): Before sending SIGTERM, the Kubelet runs the PreStop Hook. This allows the pod to perform custom tasks (e.g., closing connections) during shutdown.

SIGTERM: Kubelet sends SIGTERM, initiating a graceful shutdown. The pod is given the deletionGracePeriodSeconds (default 30s) to cleanly exit.

Graceful Shutdown: During the grace period, the pod handles any ongoing tasks, such as completing requests or saving data, before it fully stops.

SIGKILL: If the pod doesn't terminate within the grace period, SIGKILL is sent, forcing an immediate shutdown.

Pod Deleted: The API Server updates ETCD, marking the pod as deleted. Components like Kube-Proxy, Ingress, and others remove all references to the pod.

Here are some common signals for your knowledge (though out of context):

  • SIGHUP: Hangup signal
  • SIGINT: Interrupt signal (triggered by Ctrl+C)
  • SIGQUIT: Quit signal
  • SIGSTOP: Stop the process (cannot be caught or ignored)

I hope this was helpful in your learning journey. I went through an article and thought it might add some value to your learning journey so I shared it with all of you.

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (2)

Collapse
 
adam_joseph_e3d94ad3b1e49 profile image
Adam Joseph

Your answer is too much detailed but it helps a lot.

Collapse
 
pareekplatform profile image
Shubham

Thanks Adam

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more