简体   繁体   中英

Where does a kubernetes ingress gets its IP address from?

I have a typhoon kubernetes cluster on aws with an nginx ingress controller installed.

If I add an test ingress object it looks like this:

NAMESPACE   NAME   CLASS    HOSTS                ADDRESS      PORTS   AGE
default     foo    <none>   *                    10.0.8.180   80      143m

Question: Where does my ingress controller get that address(10.0.8.180) from?

There is no (loadbalancer) service on the system with that address. (Because it is a private address external-dns does not work correctly.)

In order to answer your first question:

Where does a kubernetes ingress gets its IP address from?

we have to dig a bit into the code and its behavior.

It all starts here with publish-service flag:

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.`)

The flag variable (publishSvc) is later assigned to other variable (PublishService):

PublishService: *publishSvc,

Later in the code you can find that if this flag is set, this code is being run:

if s.PublishService != "" {
return statusAddressFromService(s.PublishService, s.Client)
}

statusAddressFromService function as an argument takes value of publish-service flag and queries kubernetes for service with this name, and returns IP address of related service.

If this flag is not set it will query the k8s for IP address of a node where nginx ingress pod is running. This is the bahaviour you are experiencing and it makes me think that you didn't set this flag. This also answers your second question:

Why does it take the address of the node instead of the NLB?

Meanwhile you can find all yaml for all sort of platforms in k8s nginx ingress documentation .

Lets have a look at AWS ingress yaml . Notice here that publish-service has a value called ingress-nginx/ingress-nginx-controller (<namespace>/<service>). and this is what you also want to do.


TLDR: All you have to do is to create a LoadBalancer Service and set the publish-service to <namespace_name>/<service_name>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM