kubernetes(探测)

钩子:
post start:容器启动后钩子(容器启动后执行的操作,失败重启容器)
pre stop:容器终止前钩子(容器删除时执行的操作,失败阻塞容器删除)

exec命令方式栗子:
lifecycle: (在容器行里面,与容器名称行对齐)
postStart:
exec:
command:
- cat
- /tmp/healthy
preStop:
exec:
command: ["/usr/sbin/nginx","-s","quit"]


容器探测:
livenessProbe:存活性探测,检查容器是否运行正常,失败重启容器
readinessProbe:就绪性探测,检查容器是否可以接受请求,失败不转发流量。(有的容器启动后需要读取外部文件后,才能服务。此时就可以检查容器是否准备就绪)

探测的三种方式:
exec:命令探测
tcpSocket:socket探测
httpGet:http探测

其他配置:
initialDelaySeconds:容器启动后等待多少秒执行第一次探测
timeoutSeconds:探测超市时间,默认1秒,最小1秒
periodSeconds:执行频率,默认10秒,最小1秒
failureThreshold:连续探测失败多少次才认定失败,默认3次,最小1次
successThreshold:连续探测失败多少次才认定成功,默认1次

exec栗子:
spec:
containers:
- name: nginx
image: nginx:1.17.1
ports:
- name: nginx-port
containerPort: 80
livenessProbe:
exec:
command: ["/bin/cat","/tmp/hello.txt"]

TCPSocket栗子:
livenessProbe:
tcpSocket:
port: 8080

HTTPGet栗子:
livenessProbe:
httpGet:
scheme: HTTP
port: 80
path: //hello

posted @ 2021-06-20 23:14  丑矬穷屌  阅读(83)  评论(0)    收藏  举报