如何配置我的Deployment以对sprint引导执行器端点进行健康检查? 我正在使用在端口9000上运行的spring boot2。(PS:端口转发测试有效)
这是错误:
Readiness probe failed: Get http://10.48.0.116:9000/actuator/health: dial tcp 10.48.0.116:9000: connect: connection refused
这就是我的部署yml:
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: my-api
namespace: vidolin
labels:
stack: api
app: my-api
spec:
replicas: 1
selector:
matchLabels:
stack: api
app: my-api
template:
metadata:
labels:
stack: api
app: my-api
spec:
imagePullSecrets:
- name: itdevregistry
containers:
- name: primary
image: vidolinregistry.azurecr.io/my/api
ports:
- containerPort: 9000
envFrom:
- configMapRef:
name: my-api-config
readinessProbe:
httpGet:
path: /actuator/health
port: 9000
initialDelaySeconds: 10
timeoutSeconds: 2
periodSeconds: 3
failureThreshold: 1
livenessProbe:
httpGet:
path: /actuator/health
port: 9000
initialDelaySeconds: 20
timeoutSeconds: 2
periodSeconds: 8
failureThreshold: 1
答案 0 :(得分:1)
尽管我回复晚了一点。但是我认为我的实现将帮助人们将来为Spring Boot应用程序实现kubernetes就绪/活跃性探针。
我的docker映像的描述
所以我不能使用kubernetes的httpGet选项,因为它仅使用http协议。
这就是为什么我在docker映像中创建一个小的shell脚本“ check-if-healthy.sh”作为状态的原因
check-if-healthy.sh
===================
curl -k https://localhost:8888/actuator/health | grep '"status":"UP"' > /dev/null && exit 0 || exit 1
请注意,您需要将此脚本添加到docker映像中,以便它可以在运行的容器中使用并且可以被kubernetes访问,因为kubernetes将触发“ docker exec / bin / ash / home / config-server /检查是否健康。” 像这样
COPY docker/check-if-healthy.sh /home/config-server/check-if-healthy.sh
然后使用kubernetes准备就绪探针的“ exec”选项调用这样的脚本。
readinessProbe:
exec:
command:
- /bin/ash
- /home/config-server/check-if-healthy.sh
initialDelaySeconds: 5
timeoutSeconds: 1
failureThreshold: 50
livenessProbe:
exec:
command:
- /bin/ash
- /home/config-server/check-if-healthy.sh
initialDelaySeconds: 5
timeoutSeconds: 1
failureThreshold: 50