9.2Ready检查
kubernetes通过ready检查,检查程序是否准备好了,是否可以正常访问了,若程序已ready,则该pod将挂到负载均衡上去
ready检查通健康检查一样,同样支持基于bash、http、tcp的策略
基于bash的策略
readinessProbe:
exec:
command:
- /bin/sh
- -c
- ps -ef|grep java|grep -v grep
基于http的策略
基于http的策略:kubernetes通过发起http请求,若http的响应值为200,则认为检查通过,否则失败。
设置http策略,可按照如下方式设置deployment:
readinessProbe:
httpGet:
path: /examples/index.html
port: 8080
scheme: HTTP
注意:设置initialDelaySeconds的值时,尽量大于pod的预计启动时间
基于TCP的健康检查
基于tcp的策略:kubernetes判断port是否开启,若port开启,则认为检查通过,否则失败。
readinessProbe:
tcpSocket:
port: 8080
扩展
readinessProbe的其他参数
initialDelaySeconds:10 # 容器启动10s之后再执行
periodSecond:10 # Ready检查的间隔,每10s检查一次
failureThreshold:2 # 允许失败2次,失败次数超过2次,pod将重启
successThreshold:1 # 从错误到正确,正确执行1次,却认为pod正常
timeoutSeconds:5 # 命令的最长等待时间,执行命令时间超过5s,任务本次健康检查失败
readiness 决定了deployment 的AVAILABLE字段,已ready,则AVAILABLE为1,否则为0
[root@root ~]# kubectl get deploy -n test
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
app-4axj5 1 1 1 0 2d
Last updated
Was this helpful?