<p>Folks,
  Is there an easier method to grab the external ip address of a service in Kubernetes, than to parsing the output of a kubectl output?</p>

<p><code>kubectl get services/foo --namespace=foo -o json</code></p>

<p>Thanks!</p>

<p>Using kubectl is the easiest way to get the ingress IP addresses of your services. If you are looking to get just the IP addresses then you can do most of the parsing as part of the kubectl command itself.</p>

<pre><code>kubectl get svc foo -n foo \
    -o jsonpath="{.status.loadBalancer.ingress[*].ip}"
</code></pre>

<p>This may not apply to you but some cloud load balancers (like AWS ELB) give you a hostname rather than IP address so you will need to look for that instead.</p>

<pre><code>kubectl get svc foo -n foo \
    -o jsonpath="{.status.loadBalancer.ingress[*].hostname}"
</code></pre>

<p>You can get both by using the jsonpath union operator if you like.</p>

<pre><code>kubectl get svc foo -n foo \
    -o jsonpath="{.status.loadBalancer.ingress[*]['ip', 'hostname']}"
</code></pre>

<p>If you want a human readable output you can use the <code>custom-columns</code> output format.</p>

<pre><code>kubectl get svc foo -n foo \
    -o custom-columns="NAME:.metadata.name,IP ADDRESS:.status.loadBalancer.ingress[*].ip"
</code></pre>
