<p>I have two services (client and server) both of types of load balancer.  I would like to make the client service talking to server service. How do I do programmatically (via yaml file etc).</p>

<p>More explicitly client runs a python code in which it needs access to server's external ip. However I only know server service name not external ip.</p>

<p>of course one way to solve this issue is to launch server first and get the external ip and add it to client's yaml file. I am looking for solution like accessing external ip by just knowing the service name.  </p>

<p>Client and server resides in the same kubernetes cluster. </p>

<p><strong>Client.yaml</strong> Client runs a web server and if someone hits the url advertised by web server <code>demo.py</code> should make a call to the server's service. I was thinking of a way to get the server's <code>external-ip</code> programmatically here, however I am open for suggestions.</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name:client-deployment
spec:
  replicas: 3
  template:
    metadata:
      labels:
        app: client
    spec:
      containers:
      - name: client-container
        image: client_image:latest
        command:
          - "python"
          - "/root/demo.py"
        ports:
        - containerPort: 5000
---
apiVersion: v1
kind: Service
metadata:
  labels:
    run: client-service
  name: client-service
spec:
  ports:
  - port: 5000
    targetPort: 5000
  selector:
    app: inception-client
  type: LoadBalancer
</code></pre>

<p><strong>Server.yaml</strong>: It exposes a service at port 9000, which client should call.</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: server-deployment
spec:
  replicas: 3
  template:
    metadata:
      labels:
        app: server
    spec:
      containers:
      - name: server-container
        image: server_image:latest
        command:
        - &lt;Command to start a server which listens on port 9000&gt;
        ports:
        - containerPort: 9000
---
apiVersion: v1
kind: Service
metadata:
  labels:
    run: server-service
  name: server-service
spec:
  ports:
  - port: 9000
    targetPort: 9000
  selector:
    app: server
  type: LoadBalancer
</code></pre>

rgaut
<p>The client only needs to know the kubernetes Service name linked to the server.  Kubernetes will handle the routing to the desired server pod.  Specifying a load balancer also implicitly creates a clusterip. Which your client python application can use.</p>

<p>You can provide in your client code a readiness probe that checks if the server is up, that way you can be sure that when the server is ready, the client can also start taking requests.</p>
