2016-09-07 111 views
1

我們在Kong API網關後面有多個微服務實例,我們希望平衡用戶請求的負載。KONG API網關中的負載均衡

說微服務1在KONG API網關後面的多個實例中相乘;在這種情況下,來自用戶1的請求應該擊中第一個實例,並且來自用戶2的請求應該基於它們的可用性(負載平衡)擊中相同服務的某個其他實例。 (即)我是否可以有多個上游URL在香港的單個API。我們不想使用nginx進行負載平衡。請諮詢我們如何解決它。

+1

請關注這個問題https://github.com/Mashape/kong/issues/157 - 該功能應該在v0.10發佈 – Mark

回答

1

從0.10開始,您將能夠創建一個命名上游,並從中關聯/移除目標。

例如,如果你有upstream_url=http://helloworld/你可以創建一個helloworld上游和準目標,以它:

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/ 
+0

上游(helloworld)如何鏈接到upstream_url(http://你好,世界/)?或者上游如何鏈接到api對象? – StarCub

0

環均衡策略可以在香港使用,如果你不希望基於DNS的負載均衡。詳情請參閱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" 

請求與主機頭設置爲address.mydomain.com現在將通過香港代理到兩個定義的目標; 2/3的請求將會轉到http://192.168.34.15:80/address(權重= 100),1/3將轉到http://192.168.34.16:80/address(權重= 50)。