You are browsing documentation for an outdated version. See the latest documentation here.

Blue-green Deployments

Using the ring-balancer, a blue-green deployment can be easily orchestrated for a service. Switching target infrastructure only requires a PATCH request on a service to change its host value.

Set up the “blue” environment, running version one of the address service:

  1. Create an upstream:

    1. curl -X POST http://localhost:8001/upstreams \
    2. --data "name=address.v1.service"
  2. Add two targets to the upstream:

    1. curl -X POST http://localhost:8001/upstreams/address.v1.service/targets \
    2. --data "target=192.168.34.15:80"
    3. --data "weight=100"
    4. curl -X POST http://localhost:8001/upstreams/address.v1.service/targets \
    5. --data "target=192.168.34.16:80"
    6. --data "weight=50"
  3. Create a service targeting the Blue upstream:

    1. curl -X POST http://localhost:8001/services/ \
    2. --data "name=address-service" \
    3. --data "host=address.v1.service" \
    4. --data "path=/address"
  4. Finally, add a route as an entry-point into the service:

    1. curl -X POST http://localhost:8001/services/address-service/routes/ \
    2. --data "hosts[]=address.mydomain.com"

Requests with host header set to address.mydomain.com will now be proxied by Kong Gateway to the two defined targets. Two-thirds of the requests will go to http://192.168.34.15:80/address (weight=100), and one-third will go to http://192.168.34.16:80/address (weight=50).

Before deploying version two of the address service, set up the “Green” environment:

  1. Create a new Green upstream for address service v2:

    1. curl -X POST http://localhost:8001/upstreams \
    2. --data "name=address.v2.service"
  2. Add targets to the upstream:

    1. curl -X POST http://localhost:8001/upstreams/address.v2.service/targets \
    2. --data "target=192.168.34.17:80"
    3. --data "weight=100"
    4. curl -X POST http://localhost:8001/upstreams/address.v2.service/targets \
    5. --data "target=192.168.34.18:80"
    6. --data "weight=100"
  3. To activate the blue/green switch, we now only need to update the service. Switch the Service from Blue to Green upstream, v1 -> v2:

    1. curl -X PATCH http://localhost:8001/services/address-service \
    2. --data "host=address.v2.service"

Incoming requests with host header set to address.mydomain.com are now proxied by Kong to the new targets. Half of the requests will go to http://192.168.34.17:80/address (weight=100), and the other half will go to http://192.168.34.18:80/address (weight=100).

As always, the changes through the Kong Gateway Admin API are dynamic and take effect immediately. No reload or restart is required, and no in-progress requests are dropped.