Load Balancer for APIs

How the upstream added for ring balancer related with APIs upstream url?
e.g., If I have added an API with upstream url http://some-host.com:8181/service1 and added an upstream with name ms1 and with target some-host.com:8181, then how can I pass the upstream url? What should be correct way of using upstream?

Hi,

Your question is very vague and open-ended. Have you read the Load Balancing Reference?

Unless you have a more specific question to ask, if you are generally curious about how the Load Balancer works (or any other part of Kong really), I suggest that you read the documentation for it first.

Hi @thibaultcha,
Thanks for your reply and I am sorry for not clarifying my question.
I had read the documentation of Load Balancing. There it is written ā€œupstream: a ā€˜virtual hostnameā€™ which can be used in an API upstream_url fieldā€. So, I was not sure how this upstream can be used exactly in API upstream_url field.
Now, I think I got it. The name field of upstream could be used as hostname in upstream_url of an API.

I will edit my previous question to make it more specific.

Thanks.

I see, thanks for clarifying your question.

Well, as specified in the documentation, you tie an Upstream to an API when the Upstreamā€™s name matches the hostname in an APIā€™s upstream_url. So in your case, your Upstreamā€™s name should be some-host.com.

If that is how you configure Kong, then no DNS resolution will take place to resolve your APIā€™s upstream_url. Kong de facto uses the list of Targets associated to an Upstream to proxy a request. Targets are intended to represent physical hosts, referenced to by their IP address and port. Kong will iterate over the list of Targets associated to an Upstream in a round-robin fashion, but taking a Targetā€™s weight attribute into consideration.

Now, I hope you understand that you would have to script Kong in such a way that those Targets are added and removed appropriately by an orchestrator of your choosing (or your own in-house solution). If instead, you are using a service discovery tool (e.g., Consul), you can delete the Upstream, effectively we-enabling DNS resolution of the upstream_url by Kong, and point Kongā€™s DNS resolver to the nameserver provided by your orchestration tool. Under the hood, Kong can then load balance over A or SRV records automatically and will respect the recordsā€™ TTL values.

Now, I believe I have mostly re-stated what the referee documentation already establishes. Was anything not clear enough in the documentation that warranted your question?

1 Like

Your explanation helped me to better understand the load balancing in kong.
Thanks.