首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Kubernetes postStart生命周期总是失败

Kubernetes postStart生命周期总是失败
EN

Stack Overflow用户
提问于 2021-07-20 19:58:30
回答 2查看 542关注 0票数 2

尝试使用postStart生命周期解决pods之间的依赖关系。

使用案例:微服务A应在微服务B启动后启动。

为此,我们添加了一个容器( curl ),它将使用curl命令检查依赖服务是否启动。

但是,当我们在postStart生命周期钩子中添加任何命令时,pods会持续重启并进入崩溃回退状态

Deployment.yaml:

代码语言:javascript
运行
复制
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

在互联网上搜索此问题时发现了以下内容。

EN

回答 2

Stack Overflow用户

发布于 2021-07-20 20:52:12

您也可以在livenessProbe中使用readinessProbe,如下所示:

代码语言:javascript
运行
复制
        readinessProbe:
            httpGet:
                path: /api/health
                port: 8080
        initialDelaySeconds: 10
        periodSeconds: 5
        failureThreshold: 8

        // for tcpSocket use:
            readinessProbe:
                tcpSocket:
                    port: 3306 
票数 1
EN

Stack Overflow用户

发布于 2021-07-20 20:04:43

这是因为您在postStart中的命令休眠了10秒,而您的LivenessProbe配置为在5秒后失败。

也许可以增加initialDelaySeconds或添加failureThreshold

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68454486

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档