Kong命令(二)service


 

service介紹:

service 是聲明了一組name、host、port、protocol等配置的函數。可以綁定route、upstream上下游服務。並且對於route、upstream可以綁定多個。

新增service后,kong會自動分配一個id值,該id為service的唯一標識。可用於后期修改、查看以及綁定route、upstream。

-------------------------------------------------------------------------------------------------------------------------------------------------------------- 

命令:

kong網關的命令接口基本符合restful api風格。官網上的addservice、list service只是模塊名稱,不是命令,不要混淆。

不同的命令主要區分在http的請求方法(get、post、put、patch、delete)。

1、addservice(新增服務)

post 方法,api:http://127.0.0.1:8001/services  

參數主要放置在requestBody內。

 

上圖是使用postman發起的請求,可以看出使用的是post請求,參數放置在body里。

創建成功后,kong服務會返回此次創建成功的service的name等所有配置屬性。同時會發配一個唯一的service.id

 

這種是直接創建service,然后創建的同時通過配置一些參數設置屬性。此外還可以直接針對已存在的certificates直接創建綁定服務

(1)post 方法 api:http://127.0.0.1:8001/certificates /{certificates id}/service

    參數和直接創建service方法一致。其中certificates id就是kong服務分配給certificates 路由的唯一標識id

 

2、查看 list service 、retrieve service(檢索服務)--兩者功能類似,合並到一起

(1) get方法 api :http://127.0.0.1:8001/services

展示所有已創建的服務

(2)get方法 api:http://127.0.0.1:8001/services/{service id/name}

只展示對應service id/name的服務屬性

(3)get方法 api:http://127.0.0.1:8001/certificates/{certificates id}/services

展示與指定證書關聯綁定的服務

(4)get方法 api:http://127.0.0.1:8001/routes/{routes id}/service

檢索與指定route id綁定的服務。同樣的也可以檢索指定plugin 插件(/plugins/{plugin id}/service)的服務

 

3、修改 update service

方法 patch 。局部更新

(1)http://127.0.0.1:8001/service/{service id}

針對指定的service id修改屬性

(2)http://127.0.0.1:8001/certificates/{certificate id}/services/{service name or id}

 

(3)http://127.0.0.1:8001//plugins/{plugin id}/service

修改與指定插件的關聯的service。route與此類似。/routes/{route name or id}/service

 

4、替換(create or update service)

使用的http方法是put,結合put的用法以及api參數,我理解更偏向與對現有服務的整體創建或替換。如果指定id則是替換,沒有id則是新建

 

(1)http://127.0.0.1:8001/services/{service name or id}

(2)http://127.0.0.1:8001/certificates/{certificate id}/services/{service name or id}

(3)http://127.0.0.1:8001//routes/{route name or id}/service

  /plugins/{plugin id}/service

 

5、刪除 delete service

(1)/services/{service name or id}

(2)/certificates/{certificate id}/services/{service name or id}

(3)/routes/{route name or id}/service

 

 

 


 

人生在世,雜事七八;飯要少吃,事要多知;抽個時間,總結一下;樂在分享,自在提升 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM