【发布时间】:2018-07-30 18:51:43
【问题描述】:
我正在尝试编写一个提取负载均衡器值的 go 模板。使用--go-template={{status.loadBalancer.ingress}} 返回[map[hostname:GUID.us-west-2.elb.amazonaws.com]]% 当我将.hostname 添加到模板时,我收到一条错误消息,提示“无法在类型接口{} 中评估字段主机名”。我试过使用 range 关键字,但我似乎无法正确使用语法。
{
"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"
}
]
}
}
}
【问题讨论】: