介紹
route 是一套匹配客戶端請求的規則。每個route都會匹配一個service,每個service可定關聯多個route。
可以說service:route=1:n。一對多的關系。每個匹配到route的請求都會代理到對應的service上。
路由可以設定不同的協議,不同的協議配置的屬性不一樣。官網介紹如下:
- For
http
, at least one ofmethods
,hosts
,headers
orpaths
; - For
https
, at least one ofmethods
,hosts
,headers
,paths
orsnis
; - For
tcp
, at least one ofsources
ordestinations
; - For
tls
, at least one ofsources
,destinations
orsnis
; - For
grpc
, at least one ofhosts
,headers
orpaths
; - For
grpcs
, at least one ofhosts
,headers
,paths
orsnis
.
在kong網關服務中,可以和路由route匹配的有兩類:service和plugin
在操作route的命令中也可以依賴這兩類進行操作。命令格式和service相似,都是使用restful api風格,區分再不同的http方法。
接下來簡單介紹
1,add routes
post 方法
(1)http://127.0.0.1:8001/routes
(2)http://127.0.0.1:8001//services/{service name or id}/routes 給指定的service 添加路由
主要參數包括:name ,path(匹配該路由的路徑),host(匹配該路由的域名列表),protocols(http、https),methods,service.id
2,list routes ,Retrieve Route
get 方法
(1) http://127.0.0.1:8001/routes 展示所有routes
(2)/services/{service name or id}/routes
/routes/{route name or id}
/services/{service name or id}/routes/{route name or id}
/plugins/{plugin id}/route
以上展示指定的route信息
3,update routes 修改
方法:patch
(1)/routes/{route name or id}
(2)/services/{service name or id}/routes/{route name or id}
/plugins/{plugin id}/route
4,create or update routes 存在時更新,不存在時創建
方法:put
(1)/routes/{route name or id}
(2)/services/{service name or id}/routes/{route name or id}
/plugins/{plugin id}/route
5,delete route刪除
(1)/routes/{route name or id}
(2)/services/{service name or id}/routes/{route name or id}
人生在世,雜事七八;飯要少吃,事要多知;抽個時間,總結一下;樂在分享,自在提升