Kong是一個可伸縮的開源API層(也稱爲API網關或API中間件)。Kong最初是由Kong Inc.(前身爲Mashape)建造的,用於爲其API市場提供超過15000個微服務,每月產生數十億個請求。
在經過實戰檢驗的NGINX的支持下,該公司專注於高性能,在2015年成爲開源平臺。在積極的發展下,Kong現在已被用於從創業公司到大型企業和政府部門的數百個組織的生產,包括:《紐約時報》
支持 權限控制,安全,負載均衡,請求分發,監控,限流 等等。
github :
docker安裝 :https://github.com/Kong/docker-kong
Kong 源碼:https://github.com/Kong/kong
官網地址:https://getkong.org/
官網文檔:https://getkong.org/docs/0.12.x/proxy/
安裝:
cd /data/
git clone https://github.com/Kong/docker-kong.git
cd docker-kong/compose
docker-compose up -d
Kong 項目會監控兩個端口,一個是 8000,一個是 8001。 8000端口是可以給用戶訪問,就是說用戶發送請求先到 Kong 項目的 8000 端口,然後Kong 項目幫你轉到你的後端應用api。 8001 端口是管理端口,比如說,管理員可以通過 8001端口來得到你加入過的 api。
二:kong api 增刪改查
1、添加API
curl -i -X POST http://localhost:8001/apis/ \
-d 'name=test1' \
-d 'upstream_url=http://10.4.21.101' \
-d 'uris=/admin' \
-d 'strip_uri=false'
curl -i -X POST http://localhost:8001/apis/ \
-d 'name=test2' \
-d 'upstream_url=http://10.4.37.242' \
-d 'uris=/admin/login.html'
url:8001端口是Kong的管理端口。
name: api名稱
upstream_url:提供服務的後端url。
uris:請求的地址
strip_uri:是否截斷url # /admin/order.html 會把admin去掉
2、查詢api
curl -X GET http://localhost:8001/apis/
curl -X GET http://localhost:8001/apis/test1
3、刪除api
curl -X DELETE http://localhost:8001/apis/test1
4、更新api
curl -i -X PATCH http://localhost:8001/apis/test1 -d 'name=test3'
5、驗證 kong是否成功路由
通過上面創建的api 根據不同的URL請求到後端不同的服務器;
/admin/login.html---http://10.4.37.242
/admin 其他----http://10.4.21.101
/ {"message":"no API found with those values"}
/agent {"message":"no API found with those values"}
類似於nginx反向代理,可動態調整、相當靈活;
還有其他功能待驗證。。。。。
圖形化客戶端 工具可以管理API;