pod健康检查通过以下两类探针
-
LivenessProbe: 检查容器是否存活,如果不包含,则返回永远是Success
-
ReadinessProbe:检查容器服务是否可用,可以接受请求
实现方式
- ExceAction: 在容器内部执行一个命令,如果该命令的返回码为0,则表明容器健康。
apiVersion: v1
kind: Pod
metadata:
name: pod-health
lables: health
namespaces: test
spec:
containers:
- name: nginx-pod
image: nginx
livenessProbe:
exec:
command:
- cat
- /tmp/health
initialDelaySeconds: 80
timeoutSeconds: 10
periodSeconds: 5
readinessProbe:
httpGet:
path: /data/health
port: 8080
initialDelaySeconds: 80
timeoutSeconds: 10
periodSeconds: 5
- TCPSockerAction: 通过容器的IP地址和端口号执行TCP检查,如果能够建立TCP连接,则表明容器健康。
apiVersion: v1
kind: Pod
metadata:
name: pod-health
lables: health
namespaces: test
spec:
containers:
- name: nginx-pod
image: nginx
livenessProbe:
tcpSocket:
port: 80
initialDelaySeconds: 80
timeoutSeconds: 10
periodSeconds: 5
readinessProbe:
httpGet:
path: /data/health
port: 8080
initialDelaySeconds: 80
timeoutSeconds: 10
periodSeconds: 5
- HTTPGetAction: 通过容器的IP地址、端口号及路径调用HTTP Get方法,如果响应的状态码大于等于200且小于400,则认为容器健康。
apiVersion: v1
kind: Pod
metadata:
name: pod-health
lables: health
namespaces: test
spec:
containers:
- name: nginx-pod
image: nginx
livenessProbe:
httpGet:
path: /data/health
port: 80
initialDelaySeconds: 80
timeoutSeconds: 10
periodSeconds: 5
readinessProbe:
httpGet:
path: /data/health
port: 80
initialDelaySeconds: 80
timeoutSeconds: 10
periodSeconds: 5
参数:
- initialDelaySeconds:手册健康检查等待时间,单位s
- timeoutSecond:等待健康检查相应超时时间,单位s