Kong网关之蓝绿部署和金丝雀发布

蓝绿部署

使用upstream,可以轻松地为服务编排蓝绿部署。

设置“蓝色”环境,运行地址服务的版本v1:

# create an upstream
$ curl -X POST http://kong:8001/upstreams \
    --data "name=address.v1.service"

# add two targets to the upstream
$ curl -X POST http://kong:8001/upstreams/address.v1.service/targets \
    --data "target=192.168.34.15:80"
    --data "weight=100"
$ curl -X POST http://kong:8001/upstreams/address.v1.service/targets \
    --data "target=192.168.34.16:80"
    --data "weight=50"

# create a Service targeting the Blue upstream
$ curl -X POST http://kong:8001/services/ \
    --data "name=address-service" \
    --data "host=address.v1.service" \
    --data "path=/address"

# finally, add a Route as an entry-point into the Service
$ curl -X POST http://kong:8001/services/address-service/routes/ \
    --data "hosts[]=address.mydomain.com"

主机头设置为的请求address.mydomain.com现在将由Kong代理到两个已定义的目标;2/3的请求将转到http://192.168.34.15:80/addressweight=100),而1/3 的请求将转到 http://192.168.34.16:80/addressweight=50)。

在部署地址服务的版本v2之前,请设置“绿色”环境:

# create a new Green upstream for address service v2
$ curl -X POST http://kong:8001/upstreams \
    --data "name=address.v2.service"

# add targets to the upstream
$ curl -X POST http://kong:8001/upstreams/address.v2.service/targets \
    --data "target=192.168.34.17:80"
    --data "weight=100"
$ curl -X POST http://kong:8001/upstreams/address.v2.service/targets \
    --data "target=192.168.34.18:80"
    --data "weight=100"

要激活蓝色/绿色开关,我们现在只需要更新服务:

# Switch the Service from Blue to Green upstream, v1 -> v2
$ curl -X PATCH http://kong:8001/services/address-service \
    --data "host=address.v2.service"

主机头设置为的传入请求address.mydomain.com现在将由Kong代理到新目标;1/2的请求将转到http://192.168.34.17:80/addressweight=100),而其他1/2 的请求将转到 http://192.168.34.18:80/addressweight=100)。

与往常一样,通过Kong Admin API进行的更改是动态的,将立即生效。无需重新加载或重新启动,并且不会丢弃任何进行中的请求。

金丝雀发布

使用upstream,可以精确调整target权重,从而实现平稳释放受控的金丝雀

使用一个非常简单的2个target示例:

# first target at 1000
$ curl -X POST http://kong:8001/upstreams/address.v2.service/targets \
    --data "target=192.168.34.17:80"
    --data "weight=1000"

# second target at 0
$ curl -X POST http://kong:8001/upstreams/address.v2.service/targets \
    --data "target=192.168.34.18:80"
    --data "weight=0"

通过重复请求,但每次更改权重,流量将缓慢地路由到另一个target。例如,将其设置为10%:

# first target at 900
$ curl -X POST http://kong:8001/upstreams/address.v2.service/targets \
    --data "target=192.168.34.17:80"
    --data "weight=900"

# second target at 100
$ curl -X POST http://kong:8001/upstreams/address.v2.service/targets \
    --data "target=192.168.34.18:80"
    --data "weight=100"

通过Kong Admin API进行的更改是动态的,将立即生效。无需重新加载或重新启动,并且不会丢弃任何进行中的请求。

你可能感兴趣的:(Kong网关之蓝绿部署和金丝雀发布)