Senior
How does Kubernetes understand that a pod has died and needs to be restarted? Tell me about probes.
sobes.tech AI
Answer from AI
Kubernetes uses probes to monitor the health of containers in pods. The main types of probes:
- Liveness Probe — checks if the container is alive. If the check fails, kubelet restarts the container.
- Readiness Probe — checks if the container is ready to accept traffic. If not, services do not send requests to it.
Kubelet periodically performs these checks, for example, by sending HTTP requests, executing commands, or checking TCP connections. If the liveness probe fails, Kubernetes considers the container "dead" and starts a new instance.
Example configuration of a liveness probe in a Pod:
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 15
periodSeconds: 20
Thus, Kubernetes automatically maintains application operability by restarting containers upon failures.