<p>I'm trying to write a go template that extracts the value of the load balancer.  Using <code>--go-template={{status.loadBalancer.ingress}}</code> returns <code>[map[hostname:GUID.us-west-2.elb.amazonaws.com]]%</code> When I add <code>.hostname</code> to the template I get an error saying, "can't evaluate field hostname in type interface {}".  I've tried using the <code>range</code> keyword, but I can't seem to get the syntax right. </p>

<pre><code>{
    "apiVersion": "v1",
    "kind": "Service",
    "metadata": {
        "creationTimestamp": "2018-07-30T17:22:12Z",
        "labels": {
            "run": "nginx"
        },
        "name": "nginx-http",
        "namespace": "jx",
        "resourceVersion": "495789",
        "selfLink": "/api/v1/namespaces/jx/services/nginx-http",
        "uid": "18aea6e2-941d-11e8-9c8a-0aae2cf24842"
    },
    "spec": {
        "clusterIP": "10.100.92.49",
        "externalTrafficPolicy": "Cluster",
        "ports": [
            {
                "nodePort": 31032,
                "port": 80,
                "protocol": "TCP",
                "targetPort": 8080
            }
        ],
        "selector": {
            "run": "nginx"
        },
        "sessionAffinity": "None",
        "type": "LoadBalancer"
    },
    "status": {
        "loadBalancer": {
            "ingress": [
                {
                    "hostname": "GUID.us-west-2.elb.amazonaws.com"
                }
            ]
        }
    }
}
</code></pre>

<p>As you can see from the JSON, the ingress element is an array. You can use the <a href="https://golang.org/pkg/text/template/#hdr-Functions" rel="nofollow noreferrer">template function index</a> to grab this array element. </p>

<p>Try:</p>

<pre><code>kubectl get svc &lt;name&gt; -o=go-template --template='{{(index .status.loadBalancer.ingress 0 ).hostname}}'
</code></pre>

<p>This is assuming of course that you're only provisioning a single loadbalancer, if you have multiple, you'll have to use range</p>
