هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
The quick answer
ports:
- containerPort: 8000
startupProbe:
httpGet: { path: /healthz, port: 8000 }
periodSeconds: 5
failureThreshold: 30
readinessProbe:
httpGet: { path: /ready, port: 8000 }
periodSeconds: 5
failureThreshold: 3
livenessProbe:
httpGet: { path: /healthz, port: 8000 }
periodSeconds: 10
failureThreshold: 3
timeoutSeconds: 2Step by step
- What each probe does:
| Probe | When it fails | Use |
|---|---|---|
startupProbe | Container is restarted (after all tries). Other probes wait until it succeeds. | Slow-starting apps (Java, migrations): here up to 30 × 5 s = 150 s. |
readinessProbe | Pod is removed from the Service — no restart. | "Can I serve traffic now?" (DB reachable, caches warm). |
livenessProbe | Container is restarted. | "Am I stuck forever?" (deadlock). Keep it simple. |
- Two endpoints in the app:
/healthz(liveness): only checks the process itself — never the database. If the DB is down, restarting all Pods does not help and makes it worse./ready(readiness): may check dependencies the Pod needs to serve.
- Types of probes:
httpGet(2xx/3xx = OK),tcpSocket(port open),exec(a command returns 0),grpc.
readinessProbe:
tcpSocket: { port: 5432 }
periodSeconds: 10- Timing: liveness should be slower to fail than readiness (more
failureThresholdor a longerperiodSeconds), so a busy Pod first leaves the load balancer and only gets restarted if it really stays stuck. - Watch them work:
kubectl describe pod api-6d8f9c7b5d-x2kq9 -n shop | grep -E 'Liveness|Readiness|Startup|Unhealthy'
kubectl get endpoints api -n shop
kubectl get pods -n shop -wA Pod with a failing readiness probe shows 0/1 READY and is not in the endpoints list.
Check that it worked
During a rolling update, new Pods get traffic only after they are 1/1 READY (no errors for users), and if you make the app hang on purpose in a test, the liveness probe restarts it after period × failureThreshold seconds.
Common problems
| Problem | Cause | Fix |
|---|---|---|
| Restart loop right after start | Liveness fails before the app is up. | Add a startupProbe; do not use liveness to wait for start. |
| All Pods restart when the DB is down | Liveness checks the database. | Liveness only checks the process; DB checks go into readiness. |
| Pods restart under heavy load | Liveness timeout too short (timeoutSeconds: 1). | Longer timeout, more failures allowed; a light endpoint. |
0/1 READY forever | Readiness path/port wrong or a dependency down. | kubectl describe pod shows the probe error; test the URL inside the Pod. |
| Probe works locally but not in the cluster | App listens on 127.0.0.1. | Listen on 0.0.0.0 (the kubelet calls the Pod IP). |
| Exec probes use much CPU | Heavy command every few seconds. | Use httpGet/tcpSocket, longer period. |
Go further
- Command pages: kubectl.
- Next how-tos: Find why a Pod does not start, Roll back a deployment, Set resource requests and limits.
- Learn it: CKA — Probes, CKA — Rollouts, Docker — Health checks.
1What happens when a readiness probe fails, and when a liveness probe fails?
Readiness: the Pod gets no traffic (no restart). Liveness: the container is restarted.
2Why should a liveness probe never check the database?
If the database is down, restarting every Pod does not help and adds load; that check belongs in readiness.