概述
readinessProbe主要探测服务是否就绪,如果你的应用的readinessProbe运行失败,那么就会从组成service的端点中删除,这样就不会有流量通过Kubernetes服务发现机制来发送给它
livenessProbe探测服务是否可,不可用时重启pod
参数
- initialDelaySeconds:容器启动后,第一次执行探测需要等待多少秒
- periodSeconds:执行探测的频率,默认是10秒,最小1秒
- timeoutSeconds:探测超时时间,告诉Kubernetes应该为健康检查等待多长时间,默认1秒,最小1秒
官方文档:
支持的类型
http 请求
spec: containers: - name: liveness args: - /server image: gcr.io/google_containers/liveness readinessProbe: httpGet: path: /healthz port: 8080 httpHeaders: - name: X-Custom-Header value: Awesome initialDelaySeconds: 20 periodSeconds: 10 timeouteSeconds: 1 livenessProbe: httpGet: path: /healthz port: 8080 httpHeaders: - name: X-Custom-Header value: Awesome initialDelaySeconds: 20 periodSeconds: 10 timeouteSeconds: 1
tcp 端口
spec: containers: - name: goproxy image: gcr.io/google_containers/goproxy:0.1 ports: - containerPort: 8080 readinessProbe: tcpSocket: port: 8080 initialDelaySeconds: 20 periodSeconds: 10 timeoutSeconds: 1 livenessProbe: tcpSocket: port: 8080 initialDelaySeconds: 20 periodSeconds: 10 timeoutSeconds: 1
sh命令或shell脚本
spec: containers: - name: liveness args: - /bin/sh - -c - touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600 image: gcr.io/google_containers/busybox livenessProbe: exec: command: - cat - /tmp/healthy initialDelaySeconds: 5 periodSeconds: 5