<p>Trying to solve dependency between pods using postStart lifecycle.</p>
<p>Use case: micro service A should start after the start of micro service B.</p>
<p>For that we have added one container (curl) which will check if dependent service is up or not using curl command.</p>
<p>But when we add any command in postStart lifecycle hook, pods keep restarting and goes in crashlookbackoff state</p>
<p>Deployment.yaml :</p>
<pre><code>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: &quot;false&quot;
       proxy.istio.io/config: '{ &quot;holdApplicationUntilProxyStarts&quot;: true }'
   spec:
     containers:
       - name: curl
         image: ewoutp/docker-nginx-curl
         imagePullPolicy: IfNotPresent
         command: [ 'sh', '-c', 'touch /tmp/healthy; echo The Pod is running &amp;&amp; sleep 50' ]
         livenessProbe:
           exec:
             command:
               - cat
               - /tmp/healthy
           initialDelaySeconds: 15
           periodSeconds: 5
         lifecycle:
           postStart:
             exec:
               command: [ &quot;/bin/sh&quot;, &quot;-c&quot;, 'sleep 10;until [ $(eval curl -o -I -L -s -w &quot;%{http_code}&quot; http://microservice-B-api-service:9439/manage/health) -eq 200 ]; do echo &quot;Waiting for microservice-B API&quot;;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
</code></pre>
<p>Note: Reason for not using init-container: As we have implemented Istio with strict MTLS policy. <a href="https://github.com/istio/istio/issues/32039" rel="nofollow noreferrer">https://github.com/istio/istio/issues/32039</a></p>
<p>Found below while searching for this issue on internet.
<a href="https://i.stack.imgur.com/bbTwh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bbTwh.png" alt="enter image description here" /></a></p>

Ankita Sawant
<p>You can use readinessProbe as well with the livenessProbe like this:</p>
<pre><code>        readinessProbe:
            httpGet:
                path: /api/health
                port: 8080
        initialDelaySeconds: 10
        periodSeconds: 5
        failureThreshold: 8

        // for tcpSocket use:
            readinessProbe:
                tcpSocket:
                    port: 3306 
</code></pre>
