kubernetesclient-go

Find if pod is being terminated due to statefulset deletion


I need to perform some operations on a different server statefulset when pods inside a client statefulset comes down only because of a statefulset deletion. I can trap the sigterm signal which is sent during pod termination from inside the pod, but how do i figure out whether the termination is during a statefulset deletion because pods can come down/terminate for various other reasons. Does statefulset have its own status? because i see that statefulset status only shows the status of the pods when i do a describe. I use client-go.

Kubectl describe statefulset doesnt have a status of its own but only of the pods associated.


Solution

  • Looks like the statefulset object is deleted first and then pods are deleted in a cascading fashion. so when i trap SIGTERM, and try to query the statefulset in my code, i already receive statefulset "abc" not found. So i will use this to know that the statefulset is deleted.

    By default, Kubernetes uses background cascading deletion to delete dependents of an object https://kubernetes.io/docs/concepts/architecture/garbage-collection/#background-deletion