<p>Is there a way to request the status of a readinessProbe by using a service name linked to a deployment ? In an initContainer for example ?</p>

<p>Imagine we have a deployment X, using a readinessProbe, a service linked to it so we can request for example <code>http://service-X:8080</code>.
Now we create a deployment Y, in the initContainer we want to know if deployment X is ready. Is there a way to ask something like<code>deployment-X.ready</code> or <code>service-X.ready</code> ?</p>

<p>I know that the correct way to handle dependencies is to let kubernetes do it for us, but i have a container which doesn't crash and I have no hand on it...</p>

Borhink
<p>Instead of readinessProbe You can use just <a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/#init-containers-in-use" rel="nofollow noreferrer">InitContainer</a>.</p>
<p>You create a pod/deployment X, make service X, and create a initContainer which is searching for the service X.</p>
<blockquote>
<p>If he find it -&gt; he will make the pod.</p>
<p>If he won't find it -&gt; he will keep looking until service X will be created.</p>
</blockquote>
<p>Just a simple example, we create <a href="https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/" rel="nofollow noreferrer">nginx deployment</a> by using <code>kubectl apply -f nginx.yaml</code>.</p>
<p>nginx.yaml</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx
spec:
  selector:
    matchLabels:
      run: my-nginx
  replicas: 2
  template:
    metadata:
      labels:
        run: my-nginx
    spec:
      containers:
      - name: my-nginx
        image: nginx
        ports:
        - containerPort: 80
</code></pre>
<p>Then we create initContainer</p>
<p>initContainer.yaml</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app: myapp
spec:
  containers:
  - name: myapp-container
    image: busybox:1.28
    command: ['sh', '-c', 'echo The app is running! &amp;&amp; sleep 3600']
  initContainers:
  - name: init-myservice
    image: busybox:1.28
    command: ['sh', '-c', 'until nslookup my-nginx; do echo waiting for myapp-pod2; sleep 2; done;']
</code></pre>
<p>initContainer will look for service <strong>my-nginx</strong>, until You create it ,it will be in <code>Init:0/1</code> status.</p>
<pre><code>NAME                        READY   STATUS     RESTARTS   AGE
myapp-pod                   0/1     Init:0/1   0          15m
</code></pre>
<p>After You add service for example by using <code>kubectl expose deployment/my-nginx</code> and initContainer will find my-nginx service, he will be created.</p>
<pre><code>NAME                        READY   STATUS     RESTARTS   AGE
myapp-pod                   1/1     Running    0          35m
</code></pre>
<p>Result:</p>
<pre><code>Events:
  Type    Reason     Age        From               Message
  ----    ------     ----       ----               -------
  Normal  Scheduled  &lt;unknown&gt;  default-scheduler  Successfully assigned default/myapp-pod to kubeadm2
  Normal  Pulled     20s        kubelet, kubeadm2  Container image &quot;busybox:1.28&quot; already present on machine
  Normal  Created    20s        kubelet, kubeadm2  Created container init-myservice
  Normal  Started    20s        kubelet, kubeadm2  Started container init-myservice
  Normal  Pulled     20s        kubelet, kubeadm2  Container image &quot;busybox:1.28&quot; already present on machine
  Normal  Created    20s        kubelet, kubeadm2  Created container myapp-container
  Normal  Started    20s        kubelet, kubeadm2  Started container myapp-container
</code></pre>
<p>Let me know if that answer your question.</p>
