Note_Tech

All technological notes.


Project maintained by simonangel-fong Hosted on GitHub Pages — Theme by mattgraham

Kubernetes: Pod - Lifecycle

Back


Pod Phase

Pod Phase Description
Pending Since object is accepted, until one of the container is running
Running Since At least one of containers is running
Unknown The state of the Pod cannot be determined. Kubelet has stopped reporting.

Pod Phase Description
Succeeded All containers complete successfully
Failed At least one of the container terminates unsuccessfully

Pod Conditions

Condition Type Description
PodScheduledHas Whether the Pod been assigned to a node by the Scheduler
Initialized Whether all Init Containers have finished successfully
ContainersReady Whether all containers are in the Pod currently ready
Ready Whether the Pod’s Readiness Probes are passed
PodReadyToStartContainers Whether the sandbox and network are set up so the Kubelet can start pulling images

Lab: Pod Contidtions

kubectl run web --image=nginx
# pod/web created

kubectl describe pod web
# Conditions:
#   Type                        Status
#   PodScheduled                True
#   Initialized                 True
#   ContainersReady             True
#   Ready                       True
#   PodReadyToStartContainers   True

kubectl get pod web -o yaml
# status:
#   conditions:
#     - type: PodScheduled
#       status: "True"
#       observedGeneration: 1
#       lastTransitionTime: "2026-01-02T19:26:06Z"
#       lastProbeTime: null
#     - type: Initialized
#       status: "True"
#       observedGeneration: 1
#       lastTransitionTime: "2026-01-02T19:26:06Z"
#       lastProbeTime: null
#     - type: PodReadyToStartContainers
#       status: "True"
#       observedGeneration: 1
#       lastTransitionTime: "2026-01-03T17:28:37Z"
#       lastProbeTime: null
#     - type: ContainersReady
#       status: "True"
#       observedGeneration: 1
#       lastTransitionTime: "2026-01-03T17:28:37Z"
#       lastProbeTime: null
#     - type: Ready
#       status: "True"
#       observedGeneration: 1
#       lastTransitionTime: "2026-01-03T17:28:37Z"
#       lastProbeTime: null

Pod Lifecycle


Initialization stage

pic

Pulling the container image


Running the containers


Restarting failed init containers


Run stage

pic


post-start hook error impact a container



Pulling the container image


Running the container


Terminating and restarting the container on failures


Termination Grace Period


Termination stage


Containers Termination


Deletion Grace Period

apiVersion: v1
kind: Pod
metadata:
  name: kiada-ssl-shortgraceperiod
spec:
  terminationGracePeriodSeconds: 50
  containers:
# give the pod 10s to shut down
kubectl delete po kiada-ssl --grace-period 10

# check the log for TERM signal
kubectl logs POD_NAME -c CONTAINER_NAME -f

Lab: Pod phase

Running a pod

# demo_pod_state.yaml
apiVersion: v1
kind: Pod
metadata:
  labels:
    run: web
  name: web
spec:
  containers:
    - image: nginx
      name: web
# terminal A:
kubectl apply -f demo_pod_state.yaml
# pod/web created

# terminal B:
kubectl get pod --watch
# NAME   READY   STATUS    RESTARTS   AGE
# web    0/1     Pending   0          0s
# web    0/1     Pending   0          0s
# web    0/1     ContainerCreating   0          0s
# web    1/1     Running             0          8s

Update a pod manifest file

# demo_pod_state.yaml
apiVersion: v1
kind: Pod
metadata:
  labels:
    run: web-app # updated
  name: web
spec:
  containers:
    - image: nginx
      name: web
# terminal A:
kubectl apply -f demo_pod_state.yaml
# pod/web configured

# terminal B:
kubectl get pod --watch
# NAME   READY   STATUS    RESTARTS   AGE
# web    1/1     Running   0          14s
# web    1/1     Running   0          64s
# web    1/1     Running   0          64s
# web    1/1     Running   1 (5s ago)   69s

edit

# edit: update image: nginx:1.29.4-alpine
kubectl edit pod web
# pod/web edited

# terminal B:
kubectl get pod --watch
# NAME   READY   STATUS    RESTARTS      AGE
# web    1/1     Running   1 (42s ago)   106s

Deleting a pod

# terminal A:
kubectl delete -f demo_pod_state.yaml
# pod "web" deleted from default namespace

# terminal B:
kubectl get pod --watch
# NAME   READY   STATUS    RESTARTS        AGE
# web    1/1     Running   1 (4m50s ago)   5m54s
# web    1/1     Terminating   1 (7m12s ago)   8m16s
# web    1/1     Terminating   1 (7m12s ago)   8m16s
# web    0/1     Completed     1 (7m13s ago)   8m17s
# web    0/1     Completed     1               8m18s
# web    0/1     Completed     1               8m18s
# web    0/1     Completed     1               8m18s

Lab: Pod state - ErrImagePull

# terminal A:
kubectl run web --image=xnign
# pod/web created

kubectl delete pod web
# pod "web" deleted from default namespace

# terminal B:
kubectl get pod --watch
# NAME   READY   STATUS    RESTARTS   AGE
# web    0/1     Pending   0          0s
# web    0/1     Pending   0          0s
# web    0/1     ContainerCreating   0          0s
# web    0/1     ErrImagePull        0          1s
# web    0/1     ImagePullBackOff    0          16s
# web    0/1     ErrImagePull        0          31s
# web    0/1     ImagePullBackOff    0          42s
# web    0/1     ErrImagePull        0          56s
# web    0/1     ImagePullBackOff    0          71s
# web    0/1     ErrImagePull        0          101s
# web    0/1     ImagePullBackOff    0          116s
# web    0/1     Terminating         0          2m59s
# web    0/1     Terminating         0          2m59s
# web    0/1     Terminating         0          3m
# web    0/1     ContainerStatusUnknown   0          3m1s
# web    0/1     ContainerStatusUnknown   0          3m1s
# web    0/1     ContainerStatusUnknown   0          3m1s
# ...

Lab: Pod state - One-off Complete

# terminal A:
kubectl run demo --image=busybox --restart=Never -- sleep 10
# pod/demo created

# terminal B:
kubectl get pod --watch
# NAME   READY   STATUS    RESTARTS   AGE
# demo   0/1     Pending   0          0s
# demo   0/1     Pending   0          0s
# demo   0/1     ContainerCreating   0          0s
# demo   1/1     Running             0          3s
# demo   0/1     Completed           0          13s
# demo   0/1     Completed           0          14s
# terminal A:
kubectl get pod
# NAME   READY   STATUS      RESTARTS   AGE
# demo   0/1     Completed   0          78

kubectl delete pod demo
# pod "demo" deleted from default namespace

kubectl get pod
# No resources found in default namespace.

# terminal B:
kubectl get pod --watch
# NAME   READY   STATUS      RESTARTS   AGE
# demo   0/1     Completed   0          114s
# demo   0/1     Completed   0          2m
# demo   0/1     Completed   0          2m

Lab: Pod state - one-off Failed

# terminal A:
kubectl run demo --image=busybox --restart=Never -- slep 10 # incoreect command
# pod/demo created

kubectl get pod
# NAME   READY   STATUS               RESTARTS   AGE
# demo   0/1     ContainerCannotRun   0          67s

# terminal B:
kubectl get pod --watch
# NAME   READY   STATUS    RESTARTS   AGE
# demo   0/1     Pending   0          0s
# demo   0/1     Pending   0          0s
# demo   0/1     ContainerCreating   0          0s
# demo   0/1     ContainerCannotRun   0          3s
# demo   0/1     ContainerCannotRun   0          4s
# terminal A:
kubectl delete pod demo
# pod "demo" deleted from default namespace

kubectl get pod
# No resources found in default namespace.

# terminal B:
kubectl get pod --watch
# NAME   READY   STATUS               RESTARTS   AGE
# demo   0/1     ContainerCannotRun   0          2m42s
# demo   0/1     ContainerCannotRun   0          2m49s
# demo   0/1     ContainerCannotRun   0          2m49s