Describe what goes on in the background when a Kubernetes Pod gets deleted?
Tech Junction Answered question August 17, 2023
Here is an explanation of what happens behind the scenes when you perform the command “kubectl delete pod”:
- With ‘kubectl delete pod’ action, the pod record in ETCD will be updated by the API Server with two different fields “DeletionTimestamp” and “DeletionGracePeriodSeconds“.
- The endpoint controller checks whether the pod has reached ‘terminating state’.
- Once the state is reached, it removes the endpoint of the pod from the associated services to prevent external traffic.
- The endpoint starts getting removed from kube-proxy, IPtables, Ingress, CoreDNS and all other objects that hold endpoint information.
- Kubelet is notified of the pod being updated (Terminating).
- If the ‘preStop’ exists, the hook is executed, if not, the kubelet immediately sends a SIGTERM signal to the main container.
- After waiting for a graceful shutdown period, which is determined by the terminationGracePeriodSeconds and by default is 30 seconds, the container is forcibly stopped.
- Finally, the API Server removes the pod from ETCD completely.
Tech Junction Answered question August 17, 2023