kuberenetes中的多个活力探针 [英] Multiple liveness probes in kuberenetes
问题描述
我有一个包含多个独立的 1 组件的程序.
I have a program which has multiple independent1 components.
在所有组件中添加一个活动度探针很简单,但是拥有一个单个活动度探针来确定程序所有组件的运行状况并不容易.
It is trivial to add a liveness probe in all of the components, however it's not easy to have a single liveness probe which would determine the health of all of the program's components.
如何让kubernetes查看多个活动探针并在其中任何一个失效时重新启动容器?
How can I make kubernetes look at multiple liveness probes and restart the container when any of those are defunct?
我知道可以通过添加更多软件来实现,例如添加其他bash脚本来进行活动检查,但是我正在寻找一种本机的方式来实现此目的.
I know it can be achieved by adding more software, for example an additional bash script which does the liveness checks, but I am looking for a native way to do this.
1 独立"是指一个组件的故障不会使其他组件发生故障.
1By independent I mean that failure of one component does not make the other components fail.
推荐答案
Kubernetes API允许每个应用程序(部署/POD)具有一种活跃性和一种可读性.我建议创建一个具有端点其余部分的验证集中化服务:
The Kubernetes API allows one liveness and one readness per application (Deployment / POD). I recommend creating a validations centralizing service that has an endpoint rest:
livenessProbe:
httpGet:
path: /monitoring/alive
port: 3401
httpHeaders:
- name: X-Custom-Header
value: Awesome
initialDelaySeconds: 15
timeoutSeconds: 1
periodSeconds: 15
或尝试执行一项bash来完成相同任务,例如:
or try one bash to same task, like:
livenessProbe:
exec:
command:
- bin/bash
- -c
- ./liveness.sh
initialDelaySeconds: 220
timeoutSeconds: 5
liveness.sh
liveness.sh
#!/bin/sh
if [ $(ps -ef | grep java | wc -l) -ge 1 ]; then
echo 0
else
echo "Nothing happens!" 1>&2
exit 1
fi
回顾在事件中可以看到的有关故障的消息处理: 警告不健康的Pod Liveness探针失败:没有任何反应!"
Recalling what the handling of messages can see in the events the failure in question: "Warning Unhealthy Pod Liveness probe failed: Nothing happens!"
希望这会有所帮助
这篇关于kuberenetes中的多个活力探针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!