尝试使用postStart生命周期解决pods之间的依赖关系。
使用案例:微服务A应在微服务B启动后启动。
为此,我们添加了一个容器( curl ),它将使用curl命令检查依赖服务是否启动。
但是,当我们在postStart生命周期钩子中添加任何命令时,pods会持续重启并进入崩溃回退状态
Deployment.yaml:
kind: Deployment
metadata:
name: Microservice-A-deployment
spec:
replicas: 1
selector:
matchLabels:
app: Microservice-A
template:
metadata:
labels:
app: Microservice-A
date: 20thJune2021
annotations:
sidecar.istio.io/rewriteAppHTTPProbers: "false"
proxy.istio.io/config: '{ "holdApplicationUntilProxyStarts": true }'
spec:
containers:
- name: curl
image: ewoutp/docker-nginx-curl
imagePullPolicy: IfNotPresent
command: [ 'sh', '-c', 'touch /tmp/healthy; echo The Pod is running && sleep 50' ]
livenessProbe:
exec:
command:
- cat
- /tmp/healthy
initialDelaySeconds: 15
periodSeconds: 5
lifecycle:
postStart:
exec:
command: [ "/bin/sh", "-c", 'sleep 10;until [ $(eval curl -o -I -L -s -w "%{http_code}" http://microservice-B-api-service:9439/manage/health) -eq 200 ]; do echo "Waiting for microservice-B API";sleep 10; done; exit 0' ]
- name: Microservice-A
image: microserviceA:latest
imagePullPolicy: Always
ports:[![enter image description here][1]][1]
- name: port
containerPort: 8080
livenessProbe:
httpGet:
path: /actuator/health
port: 8080
initialDelaySeconds: 120
periodSeconds: 30
timeoutSeconds: 30
imagePullSecrets:
- name: dockersecret注意:不使用init-container的原因:因为我们使用严格的MTLS策略实现了Istio。https://github.com/istio/istio/issues/32039
在互联网上搜索此问题时发现了以下内容。

发布于 2021-07-20 20:52:12
您也可以在livenessProbe中使用readinessProbe,如下所示:
readinessProbe:
httpGet:
path: /api/health
port: 8080
initialDelaySeconds: 10
periodSeconds: 5
failureThreshold: 8
// for tcpSocket use:
readinessProbe:
tcpSocket:
port: 3306 发布于 2021-07-20 20:04:43
这是因为您在postStart中的命令休眠了10秒,而您的LivenessProbe配置为在5秒后失败。
也许可以增加initialDelaySeconds或添加failureThreshold。
https://stackoverflow.com/questions/68454486
复制相似问题