Pod`s Lifecycle

Reading Time: 3 minutes

In Kubernetes, Pod is the atomic unit of scheduling. It’s the smallest and the simplest unit in Kubernetes that you create and deploy. A Pod represents a single instance of a running process in your cluster.

Pods contain one or more containers, It is transient by nature therefore if a pod fails, Kubernetes can automatically create a new replica of that pod to continue operations.

A pod never heal itself in other words, when a pod get scheduled on the node and then fails, It then gets deleted therefore a pod doesn’t survive if there is a lack of resources either on the namespace or the node level.

Phases of pod`s Lifecycle

Pending State :

If a pod is currently in the pending state. It means that the pod has been accepted by the cluster or Kubernetes system. The pod remains in the pending state until the containers are started.

Running State :

All the containers in the pod created. The pod has been schedule on a node however most importantly at least one of the containers define is still running.

Succeeded State :

The pod has performed the task. All the container(s) exited or terminated with status 0 and after that marked as Succeeded.

Failed State :

This is the situation when all the containers are exited or terminated but one or more container(s) have returned back with a non-zero status.

Unknown State :

The container fails to start but tried to restart again and again. The kubelet is unable to get the state of the pod due to some reasons.

Activities During a pod`s lifecycle

Init Container

Init container are container that are run before the main application container started. They have two prominent characteristics:

  • It always run to completion.
  • Each init container must before the next one started.

Init container can be useful when some initial actions needs to be run before main container in pod starts.

for example : An init container is a good tool for delaying the application start until one or more dependencies are available or

Cloning a git repository into a volume, etc

Container Hooks

Container hooks provide information to the container about events in its management lifecycle. These hooks are distributes into the container with information about the life cycle of the container. There are periodically two container hooks :

  1. PostStart : This hook is sent instantly after a container is created. It inform the container about its creation. No parameter are pass to the handler.
  2. PreStop : This hook is invokes immidiately before a container is terminates. No parameters are pass to the handler.

Container probes

A probe is a diagnose performs periodically by the kubelet on a container. To perform a diagnostic, the kubelet invoked a handler executed by the container.

There are three types of handlers:

1.ExecAction

2.TCPSocketAction

3.HTTPGetAction

Termination of pod

A pod can be terminates at any time due to either scaling policy or manual pod deletion.

Conclusion

So there you have a brief overview of the Pod`s Lifecycle.Hopefully, This will give you a better understanding of the Lifecycle and its different phases as well as the activities that happens during the pod` lifecycle.

Written by 

Hi community, I am sachin from Ghaziabad a tech enthusiastic trying to make something useful for you.