Quick start with Kubernetes pod lifecycle

Table of contents
Reading Time: 2 minutes

What is Kubernetes ?

Kubernetes, also known as K8s, is an open-source system for automating deployment, scaling, and management of containerized applications.

What is a Pod in kubernetes ?

Pods are the smallest, most basic deployable objects in Kubernetes. A Pod represents a single instance of a running process in your cluster. Pods contain one or more containers, such as Docker containers. When a Pod runs multiple containers, the containers are managed as a single entity and share the Pod’s resources.

Pod Lifecycle

A pods follow a defined lifecycle, starting in the Pending phase, moving through Running if at least one of its primary containers starts OK, and then through either the Succeeded or Failed phases depending on whether any container in the Pod terminated in failure.

HI Readers, today we are going to have a discussion over Kubernetes Pod life cycle and the reason of each stage that a pod goes through in its life cycle.

The main stages through which a pod can go through are listed below.

  • Pending
  • ContainerCreating
  • Image pull
  • ErrImagePull
  • ImagePullBackOff
  • Running
  • CrashLoopBackOff
  • Terminating

Pending : If a Pod is stuck in Pending it means that it can not be scheduled onto a node.
Generally this is because there are insufficient resources of one type or another that prevent scheduling

command to check pod
#kubectl get events --all-namespaces --sort-by='.metadata.creationTimestamp'

ContainerCreating : starts creating container.

Image pull: if image pull succeed then container created
ErrImagePull : either image is not exist or login failed to registry

ImagePullBackOff: Here are some of the possible causes behind your pod getting stuck in the ImagePullBackOff state:

Image doesn't exist.
Image tag or name is incorrect.
Image is private, and there is an authentication failure.
Network issue.
Registry name is incorrect.
Container registry rate limits.

Running: The Running status indicates that a container is executing without issues.

CrashLoopBackOff : is a common error that you may have encountered when running
your first containers on Kubernetes. This error indicates that a pod failed to start,
Kubernetes tried to restart it, and it continued to fail repeatedly
your application crashed not started
if its API and trying to establish connection to external DB and connection is not established.

Terminating: Kubernetes marks the Pod state as “Terminating” and stops sending traffic to the Pod.
Kubernetes send a TERM signal to the Pod, indicating that the Pod should shut down.
When the grace period expires, Kubernetes issues a SIGKILL to any processes still running in the Pod.

Please refer this official link for more information.