Pods follow a defined lifecycle, starting in the Pending phase, moving through Running phase, and then through either the Succeeded or Failed phases.
Pod Lifecycle and Probes
Pod Phases
- Pending
- When a pod is first created, it is in a Pending state.
- The pod has been accepted by the cluster, but one or more of the containers has not been set up and made ready to run.
- If a pod is stuck in a pending state, run the kubectl describe pod command, and it will tell you exactly why.
- Running
- The pod is bound to a node.
- Once all the containers in a pod start, it goes into a running state.
- Succeeded
- All containers in the pod have terminated successfully.
- Failed
- At least one container has terminated in failure.
- Unknown
- The state of the pod cannot be obtained.
Container States
- Waiting
- The container is still running the startup operations
- Running
- The container is executing without issues.
- Terminated
- The execution has been completed or failed.
Pod Conditions
- PodScheduled
- When a pod is scheduled on a Node, the PodScheduled condition is set to true.
- ContainersReady
- When all the containers in the pod are ready, the ContainersReady condition is set to true and finally the pod itself is considered to be Ready.
- Initialized
- All init containers have started successfully.
- Ready
- The Ready condition indicates that the applications inside the pod are running and are ready to accept user traffic.
Readiness/Liveness Probes
You can specify the mechanism to check whether a pod is ready (when starting) and healthy (periodically). Probes determine the status of containers.
- Readiness Probe: determines if a pod can start to receive requests
- Liveness Probe: determines if a pod is healthy and running as expected
Probe Actions
- HTTP Test
- TCP Test
- Execute Command
Probe Result
- Success
- Failure
- Unknown
spec:
containers:
- name: my-web
readinessProbe:
httpGet:
path: /api/ready
port: 8001
livenessProbe:
httpGet:
path: /index.html
port: 8001
initialDelaySeconds: 15 # wait 15 seconds
timeoutSeconds: 2 # timeout after 2 seconds
periodSeconds: 10 # check every 10 seconds
failureThreshold: 3 # allow 3 failures
spec:
containers:
- name: my-app
readinessProbe: # or livenessProbe:
tcpSocket:
port: 3001
spec:
containers:
- name: my-web
readinessProbe: # or livenessProbe:
exec:
command:
- cat
- /api/ready