3

We have multiple instance of a micro service behind the Kong API gateway where we want to balance the load for the user requests.

Say Micro service 1 is multiplied in multiple instances which are kept behind the KONG API gateway; in such case the request from user 1 should hit the first instance and the request from user 2 should hit some other instance of same service based on their availability (load balancing). (ie) Whether can i have multiple upstream URL for a single API in kong. we dont want to use nginx for load balancing. Please advice how can we solve it.

Muthu
  • 31
  • 1
  • 1
  • 4
  • 1
    Keep an eye on this issue https://github.com/Mashape/kong/issues/157 - this feature should be released in v0.10 – Mark Sep 22 '16 at 04:44

2 Answers2

5

Ring-balancer Strategy can be used in Kong if you don't want DNS-based loadbalancing. For details please refer to Kong Load Balancing Reference!

# create an upstream
$ curl -X POST http://kong:8001/upstreams \
    --data "name=address.v1.service"

# add two targets to the upstream
$ curl -X POST http://kong:8001/upstreams/address.v1.service/targets \
    --data "target=192.168.34.15:80"
    --data "weight=100"
$ curl -X POST http://kong:8001/upstreams/address.v1.service/targets \
    --data "target=192.168.34.16:80"
    --data "weight=50"

# create an API targeting the Blue upstream
$ curl -X POST http://kong:8001/apis/ \
    --data "name=address-service" \
    --data "hosts=address.mydomain.com" \
    --data "upstream_url=http://address.v1.service/address"

Requests with host header set to address.mydomain.com will now be proxied by Kong to the two defined targets; 2/3 of the requests will go to http://192.168.34.15:80/address (weight=100), and 1/3 will go to http://192.168.34.16:80/address (weight=50).

flguo
  • 101
  • 1
  • 4
2

Starting from 0.10 you will be able to create a named upstream, and associate/remove targets from it.

For example if you have upstream_url=http://helloworld/ you can create a helloworld upstream and associate targets to it:

curl -d "name=helloworld" 127.0.0.1:8001/upstreams
curl -d "host=some.host.com" 127.0.0.1:8001/upstreams/helloworld/targets/
curl -d "host=2.2.2.2" 127.0.0.1:8001/upstreams/helloworld/targets/
Mark
  • 67,098
  • 47
  • 117
  • 162
  • how is the upstream (helloworld) linked to upstream_url (http://helloworld/)? Or how is the upstream linked to the api object? – StarCub Apr 19 '17 at 03:43