kong

kong文档1
kong文档2
# 创建名为uckendo-service的service,上游地址:http://uckendo.com
shell> curl -i -X POST --url http://localhost:8001/services --data 'name=uckendo-service' --data 'url=http://uckendo.com'

# 创建uckendo-service的路由
shell> curl -i -X POST --url http://localhost:8001/services/uckendo-services/routes --data 'hosts[]=uckendo.com' --data "name=routeone"

# 创建uckendo-service的插件key-auth
shell> curl -i -X POST --url http://localhost:8001/services/uckendo-service/plugins --data 'name=key-auth'

# 创建uckendo-service的插件basic-auth
shell> curl -i -X POST --url http://localhost:8001/services/uckendo-service/plugins --data 'name=basic-auth'

# 创建路由的插件key-auth
shell> curl -i -X POST --url http://localhost:8001/routes/routeone/plugins --data 'name=key-auth'

# 创建路由的插件basic-auth
shell> curl -i -X POST --url http://localhost:8001/routes/routeone/plugins --data 'name=basic-auth'
 --data "config.hide_credentisals=true"

# 创建消费者
shell> curl -i -X POST --url http://localhost:8001/consumers --data 'username=uckendo'

# 为消费者提供密钥凭证
shell> curl -i -X POST --url http://localhost:8001/consumers/uckendo/key-auth --data 'key=uckendo.com'

# 验证key-auth是否通过
shell> curl -i -X GET --url http://localhost:8000 --header "Host:example.com" --header "apikey:uckendo.com"

# 开启速率限制
shell> curl -i -X POST --url http://localhost:8001/services/uckendo-service/plugins --data "name=rate-limiting" --data "config.second=5" --data "config.hour=10000"

蓝绿部署

创建蓝色环境

# 创建一个upstream
shell> curl -X POST http://localhost:8001/upstreams --data "name=uckendo.v1.service"
# 给upstream添加target
shell> curl -X POST http://localhost:8001/upstreams/uckendo.v1.service/targets -d "target=192.168.101.28:80" -d "weight=50"
shell> curl -X POST http://localhost:8001/upstreams/uckendo.v1.service/targets -d "target=192.168.101.29:80" -d "weight=50"
# 创建一个以uckendo.v1.service为上游的service
shell> curl -X POST http://localhost:8001/services -d "name=uckendo-service" -d "host=uckendo.v1.service"
# 给上边创建的service添加route
shell> curl -X POST http://localhost:8001/services/uckendo-services/routes -d "hosts[]=uckendo.com"

# 发送到uckendo.com的请求,会被kong,转发到uckendo.v1.service,然后再按权重转发到upstream里的target

创建绿色环境

# 重新创建一个upstream
shell> curl -X POST http://localhost:8001/upstreams --data "name=uckendo.v2.service"
# 给upstream添加target
shell> curl -X POST http://localhost:8001/upstreams/uckendo.v2.service/targets -d "target=192.168.101.30:80" -d "weight=50"
shell> curl -X POST http://localhost:8001/upstreams/uckendo.v2.service/targets -d "target=192.168.101.31:80" -d "weight=50"

蓝绿切换

# 修改uckendo-services的host,服务从v1->v2
shell> curl -X PATCH http://localhost:8001/services/uckendo-service -d "host=uckendo.v2.service"

金丝雀版本

# 循环修改权重
shell> curl -X POST http://localhost:8001/upstreams/uckendo.v2.service/targets -d "target=192.168.101.30:80" -d "weight=60"
shell> curl -X POST http://localhost:8001/upstreams/uckendo.v2.service/targets -d "target=192.168.101.31:80" -d "weight=40"

shell> curl -X POST http://localhost:8001/upstreams/uckendo.v2.service/targets -d "target=192.168.101.30:80" -d "weight=70"
shell> curl -X POST http://localhost:8001/upstreams/uckendo.v2.service/targets -d "target=192.168.101.31:80" -d "weight=30"