# How Kubernetes pod get terminated

#### 1 State change and preparation

The pod is set to `Terminating`. And it will be isolated from end points

#### 2 Run a preStop Hook

[preStopHook](https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks) will be executed. It is special command or http request sent to containers in the pod.

#### 3 SIGTERM signal is sent to the pod

Kubernetes sends SIGTERM signal to all the containers in the pod. This lets them know that they are going to be terminated. SIGTERM can be handled, or ignored.

#### 4 Kuberntes waits for the grace period

```
apiVersion: v1
kind: pod
metadata:
  name: app-pod
spec:
  containers:
  - name: app-container
    image: busybox
  terminationGracePeriodSeconds: 60
```

#### 5 Kubernetes sends SIGKILL command

If the containers are still running it sends SIGKILL command. Kubernetes cleanup all the objects related to the terminated pod.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://i.janardhanpulivarthi.com/season-2/how-kubernetes-pod-get-terminated.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
