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 增刪改查 一、添加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去掉 二、查詢api curl -X GET http://localhost:8001/apis/ curl -X GET http://localhost:8001/apis/test1 三、刪除api curl -X DELETE http://localhost:8001/apis/test1 四、更新api curl -i -X PATCH http://localhost:8001/apis/test1 -d 'name=test3'
五、驗證 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;