为了回答你的第一个问题:
kubernetes 入口从哪里获取其 IP 地址?
我们必须深入研究代码及其行为。
这一切都以here 和publish-service 标志开始:
publishSvc = flags.String("publish-service", "",
`Service fronting the Ingress controller
Takes the form "namespace/name". When used together with update-status, the
controller mirrors the address of this service's endpoints to the load-balancer
status of all Ingress objects it satisfies.`)
标志变量(publishSvc)后来assigned到其他变量(PublishService):
PublishService: *publishSvc,
在后面的代码中你会发现如果设置了这个标志,this code 正在运行:
if s.PublishService != "" {
return statusAddressFromService(s.PublishService, s.Client)
}
statusAddressFromService function作为参数,取publish-service标志的值,向kubernetes查询该名称的服务,并返回相关服务的IP地址。
如果是flag is not set,它将在 k8s 中查询运行 nginx 入口 pod 的节点的 IP 地址。这是你正在经历的行为,它让我觉得你没有设置这个标志。这也回答了你的第二个问题:
为什么取的是节点的地址而不是NLB?
同时你可以在k8s nginx ingress documentation找到所有平台的所有yaml。
让我们看看AWS ingress yaml。
请注意,publish-service 有一个名为 ingress-nginx/ingress-nginx-controller (/) 的值。
这也是你想做的。
TLDR:您所要做的就是创建一个 LoadBalancer 服务并将 publish-service 设置为 /