startupProbe
探测容器中的应用是否已经启动。如果提供了启动探测,启动探测成功前,禁用其他所有探测。如果启动探测失败,kubelet将杀死容器,容器根据重启策略重启。如果容器没有配置启动探测,默认状态为Success.
startup 探测模式
- exec: 在容器执行指令,如果执行成功,退出码为0,则探测成功
- TCPSocket: 通过容器IP地址和端口号执行TCP检查,如果能够建立TCP连接,则表明容器健康
- HTTPGet: 通过容器IP地址、端口号及路径调用HTTP Get方法,如果响应状态码大于等于200且小于400,则认为容器健康
探测结果
- success: 符合探测预期
- failure:未通过探测
- unknown:探测未正常进行
探针属性值
- initialDelaySeconds : 容器启动后要等待多少秒后探针开始工作
- periodSeconds: 执行探测的时间间隔,默认10s
- timeoutSeconds: 探针执行探测请求后,等待响应的超时时间
- failureThreshold: 探测失败的重试次数,重试一定次数后认为未通过探测
startupprobe 案例
- exec 探测方法
[root@k8smaster4 taints]# vi startup.yaml
apiVersion: v1
kind: Pod
metadata:
name: startup-demo
namespace: default
labels:
name: test
app: myapp
spec:
containers:
- name: startup
image: docker.io/xianchao/tomcat-8.5-jre8:v1
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
startupProbe:
exec:
command:
- "/bin/sh"
- "-c"
- "ps znf | grep tomcat"
initialDelaySeconds: 20 # 容器启动后,多久开始探测
periodSeconds: 20 # 执行探测的时间间隔
timeoutSeconds: 10 # 探测执行检测请求后,等待响应时间
successThreshold: 1 # 成功多少次才是成功
failureThreshold: 3 # 失败多少次才是失败
- tcpSocket 探测方法
[root@k8smaster4 taints]# cat tcpsocket.yaml
apiVersion: v1
kind: Pod
metadata:
name: tcpSocket-demo
namespace: default
label:
environment: test
function: protection
spec:
container:
- name: tomcat-protection
image: docker.io/xianchao/tomcat-8.5-jre8:v1
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
startupProbe:
tcpSocket:
port: 8080
initialDelaySeconds: 20
periodSecondes: 20
timeoutSeconds: 10
successThreshold: 1
failureThreshold: 3
- httpGet 探测方法
[root@k8smaster4 taints]# cat httpget.yaml
apiVersion: v1
kind: Pod
metadata:
name: httpservice
namespace: default
labels:
environment: httpget
app: test
spec:
containers:
- name: httpget
image: docker.io/xianchao/tomcat-8.5-jre8:v1
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
startupProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 20
periodSeconds: 20
timeoutSeconds: 10
successThreshold: 1
failureThreshold: 3