Liveness Probe
一句话解释
liveness probe 检查如果容器是 still 运行 properly; 如果它 失败, Kubernetes restarts 容器.
用大白话说
A liveness probe is a Kubernetes mechanism that checks whether your container is alive and healthy. If the probe fails, Kubernetes kills and restarts the container — this is called self-healing.
这个is useful for catching deadlocks, memory leaks, or other situations where the process is still running but is not functioning. Without a liveness probe, a deadlocked process would stay running forever, not serving any requests.
A liveness probe can be an HTTP request, a TCP check, or a command executed inside the container. For example, you might check /health — if it returns 200, the container is alive; if it returns non-200 or times out, Kubernetes restarts it.
示例
apiVersion: v1
kind: Pod
metadata:
name: my-app
spec:
containers:
- name: my-app
image: my-app:latest
livenessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 30
periodSeconds: 10这个 liveness probe calls /health on port 8080 每个 10 seconds 之后初始 30-其次 delay. 如果它 失败, 容器是 restarted.
工作原理
- Kubernetes calls the liveness probe at regular intervals.
- If the probe succeeds, the container is considered alive.
- If the probe fails, Kubernetes kills the container.
- The container restarts (according to its restartPolicy).
常见混淆
容易混淆的对象: Readiness Probe
关键区别: liveness probe determines 如果容器应该是 restarted; readiness probe determines 如果容器应该接收 traffic. 容器能 是 alive 但不 ready.
相关术语
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。