我的应用程序的Kubernetes部署正常。
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
...
template:
...
spec:
containers:
- name: my-app
image: my-image
...
readinessProbe:
httpGet:
port: 3000
path: /
livenessProbe:
httpGet:
port: 3000
path: /
应用部署时,我可以看到部署正常运行,并且应用程序响应了我的请求。
$ kubectl describe pod -l app=my-app
...
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 4m7s default-scheduler Successfully assigned XXX
Normal Pulled 4m5s kubelet, pool-standard-4gb-2cpu-b9vc Container image "my-app" already present on machine
Normal Created 4m5s kubelet, pool-standard-4gb-2cpu-b9vc Created container my-app
Normal Started 4m5s kubelet, pool-standard-4gb-2cpu-b9vc Started container my-app
该应用程序存在缺陷,在某些情况下会崩溃。我“调用”这样的条件,然后在pod事件中看到以下内容:
$ kubectl describe pod -l app=my-app
...
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 6m45s default-scheduler Successfully assigned XXX
Normal Pulled 6m43s kubelet, pool-standard-4gb-2cpu-b9vc Container image "my-app" already present on machine
Normal Created 6m43s kubelet, pool-standard-4gb-2cpu-b9vc Created container my-app
Normal Started 6m43s kubelet, pool-standard-4gb-2cpu-b9vc Started container my-app
Warning Unhealthy 9s kubelet, pool-standard-4gb-2cpu-b9vc Readiness probe failed: Get http://10.244.2.14:3000/: net/http: request canceled (Client.Timeout exceeded while awaiting headers)
Warning Unhealthy 4s (x3 over 14s) kubelet, pool-standard-4gb-2cpu-b9vc Liveness probe failed: Get http://10.244.2.14:3000/: net/http: request canceled (Client.Timeout exceeded while awaiting headers)
Normal Killing 4s kubelet, pool-standard-4gb-2cpu-b9vc Container crawler failed liveness probe, will be restarted
预计活动性探针将失败,并且容器将重新启动。但是为什么我看到Readiness probe failed
事件?
答案 0 :(得分:1)
就绪探针用于确定容器是否准备好处理请求。您的容器可以运行,但不能通过探针。如果未通过检查,则没有服务将重定向到该容器。
默认情况下,准备就绪探测的时间为10秒。
您可以在此处了解更多信息:https://docs.openshift.com/container-platform/3.9/dev_guide/application_health.html
答案 1 :(得分:1)
正如@suren在评论中所写,启动容器后,仍将执行就绪探针。因此,如果同时定义了活跃性和就绪性探针(并且fx相同),则就绪性和活跃性探针都会失败。
答案 2 :(得分:0)
您为“准备情况和活跃性”探针配置了相同的检查-因此,如果活跃性检查失败,则可以认为准备就绪也失败。
答案 3 :(得分:0)
请在后端提供一个实现功能/方法,您可以将/ health命名为uri,并可以在此处编写活动逻辑,并且就绪状态也是您的选择。
/ health uri,应与一个函数实现相关联,如果一切正常,该函数实现将返回200状态代码,否则将导致失败