Senior
Tell about the lifecycle of a pod in Kubernetes. What are liveness and readiness probes?
sobes.tech AI
Answer from AI
The lifecycle of a pod in Kubernetes includes the following main stages:
- Pending — the pod is created, but containers are not yet started.
- Running — containers are started and running.
- Succeeded — containers have completed successfully.
- Failed — containers have terminated with an error.
- Unknown — the state cannot be determined.
Liveness probe — a check to see if the container is alive. If the check fails, kubelet restarts the container. This helps detect situations where the container is "hung" or in a non-working state.
Readiness probe — a check to see if the container is ready to accept traffic. If the check fails, the pod is excluded from services and load balancers, but the container is not restarted. This allows controlling when the application is ready to serve requests.
Example configuration of probes:
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 15
periodSeconds: 20
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 10