<p>Creating a <a href="http://kubernetes.io/v1.1/docs/user-guide/services.html#type-loadbalancer" rel="noreferrer">Kubernetes LoadBalancer</a> returns immediatly (ex: <code>kubectl create -f ...</code> or  <code>kubectl expose svc NAME --name=load-balancer --port=80 --type=LoadBalancer</code>).</p>

<p>I know a manual way to wait in shell:</p>

<pre><code>external_ip=""
while [ -z $external_ip ]; do
    sleep 10
    external_ip=$(kubectl get svc load-balancer --template="{{range .status.loadBalancer.ingress}}{{.ip}}{{end}}")
done
</code></pre>

<p>This is however not ideal:</p>

<ul>
<li>Requires at least 5 lines Bash script.</li>
<li>Infinite wait even in case of error (else requires a timeout which increases a lot line count).</li>
<li>Probably not efficient; could use <code>--wait</code> or <code>--wait-once</code> but using those the command never returns.</li>
</ul>

<p>Is there a better way to wait until a service <em>external IP</em> (aka <em>LoadBalancer Ingress IP</em>) is set or failed to set?</p>

<p>Just to add to the answers here, the best option right now is to use a bash script. For convenience, I've put it into a single line that includes exporting an environmental variable. </p>

<p><strong>Command to wait and find Kubernetes service endpoint</strong></p>

<pre><code>bash -c 'external_ip=""; while [ -z $external_ip ]; do echo "Waiting for end point..."; external_ip=$(kubectl get svc NAME_OF_YOUR_SERVICE --template="{{range .status.loadBalancer.ingress}}{{.ip}}{{end}}"); [ -z "$external_ip" ] &amp;&amp; sleep 10; done; echo "End point ready-" &amp;&amp; echo $external_ip; export endpoint=$external_ip'
</code></pre>

<p>I've also modified your script so it only executes a wait if the ip isn't available. The last bit will export an environment variable called "endpoint"</p>

<p><strong>Bash Script to Check a Given Service</strong></p>

<p>Save this as <code>check-endpoint.sh</code> and then you can execute <code>$sh check-endpoint.sh SERVICE_NAME</code></p>

<pre><code>#!/bin/bash
# Pass the name of a service to check ie: sh check-endpoint.sh staging-voting-app-vote
# Will run forever...
external_ip=""
while [ -z $external_ip ]; do
  echo "Waiting for end point..."
  external_ip=$(kubectl get svc $1 --template="{{range .status.loadBalancer.ingress}}{{.ip}}{{end}}")
  [ -z "$external_ip" ] &amp;&amp; sleep 10
done
echo 'End point ready:' &amp;&amp; echo $external_ip
</code></pre>

<p><strong>Using this in a Codefresh Step</strong></p>

<p>I'm using this for a Codefresh pipeline and it passes a variable $endpoint when it's done. </p>

<pre><code>  GrabEndPoint:
    title: Waiting for endpoint to be ready
    image: codefresh/plugin-helm:2.8.0
    commands:
      - bash -c 'external_ip=""; while [ -z $external_ip ]; do echo "Waiting for end point..."; external_ip=$(kubectl get svc staging-voting-app-vote --template="{{range .status.loadBalancer.ingress}}{{.ip}}{{end}}"); [ -z "$external_ip" ] &amp;&amp; sleep 10; done; echo "End point ready-" &amp;&amp; echo $external_ip; cf_export endpoint=$external_ip'
</code></pre>
