k8s使用存活探針livenessProbe進行pod存活性檢測,使用就緒探針確保未就緒的pod不會被加入service的后端。啟動探針確保程序啟動后才開始剩下倆種探針的探測,啟動探針一般用的比較少。
使用示例:
在spec.container下:
---
tcp探測
livenessProbe:
failureThreshold: 3 /失敗三次算真正失敗
initialDelaySeconds: 30 /第一次探測等待30秒
periodSeconds: 10 /每次間隔10秒
successThreshold: 1 /成功一次算真正成功
tcpSocket:
port: 10018 /tcp探測10018
timeoutSeconds: 2 /2秒算超時
---
http探測
ports:
- name: internal-port
containerPort: 8080
hostPort: 8080
readinessProbe:
failureThreshold: 5 /失敗5次算真正失敗
httpGet:
path: /health
port: internal-port /這里引用上面的ports信息
scheme: HTTP
initialDelaySeconds: 3 /第一次檢測等待3秒
periodSeconds: 5 /每次間隔5秒
successThreshold: 1 /成功一次即成功
timeoutSeconds: 1 /超時一秒失敗一次
---
命令探測
livenessProbe:
exec:
command:
- cat
- /tmp/healthy
initialDelaySeconds: 5 /第一次檢測等待5秒
periodSeconds: 5 /每5秒檢測一次
---
參考文檔:https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/