Deploying Blue-Green App

Apcera supports blue-green deployments using route weighting.

A blue-green deployment is an approach to deploying an updated version of a web application application that minimizes potential downtime and risk. You start with the current ("blue") version of an application that is receiving all of the external traffic at a given route ("myapp.example.me", for example). A new ("green") version of the application is deployed at the same route, but initially receives no traffic. Gradually, the amount of traffic routed to the "green" app is increased to 100 (all traffic), while the amount routed to "blue" is decreased to 0 (no traffic).

This tutorial uses APC to perform the deployment. You can also perform a blue-green deployment from the Web Console. See Managing Job Routes for more information.

Deploy app versions

To perform a blue-green deployment using APC, follow these instructions.

1) Deploy the "blue" version of the sample java-web-app with a route.

  1. Change to the sample-apps/example-java-web app folder:
    cd \sample-apps\example-java-web
    
  2. Create the application, replacing your domain name in the route URL. For example, if example.com is your Apcera cluster's domain:

     apc app create hello-blue --routes blue.example.com --start --batch
    
  3. Once deployed open the route in a browser and verify deployment. You should see "Hello World."

2) Update the app.

  1. Open example-java-web\HelloWorld.java in a text editor.
  2. Change the string displayed by the println() method from "Hello World" to "Hello Universe.", for example:
    response.getWriter().println("<h1>Hello Universe</h1>");
    
  3. Save the changes.

3) Deploy the "green" version of the app and disable default route generation.

apc app create hello-green --disable-routes --batch

By default, when you create an app it is assigned a default route. In this case, we want the "green" app's route to be the same as the "blue" app's route, so we disable default route generation with the --disable-routes option (see Default Routes and Ports for more information).

4) Expose a port on green app.

apc job update hello-green --port-add 0

The --port-add 0 option means that Apcera will randomly select an available port and provide it to the application on its $PORT environment variable. You can also select a specific port, like 8080.

5) Start the green app.

apc job start hello-green

Add route and weights

6) Add the blue route to the green app and set its weight.

apc route add blue.example.com --app hello-green --weight 25
Route Type (http/tcp) [http]:
Https Only [false]:
App Name [hello-green]:
Endpoint [blue.example.com]:
Port Number (on app) [choose open port]:
Weight (%) [25]:
╭────────────────────────────────────╮
│         Route Add Settings         │
├─────────────────┬──────────────────┤
│       App Name: │ hello-green      │
│       App Port: │ (auto-detected)  │
│     Route Type: │ http             │
│     Https Only: │ false            │
│ Route Endpoint: │ blue.example.com │
│   Route Weight: │ 25%              │
╰─────────────────┴──────────────────╯

Is this correct? [Y/n]:
Adding route http://blue.example.com to app hello-green... done
Success!

7) Check the route weights.

To see the current route weighting for each app, use the route show <route> command:

apc route show blue.example.com
Route Type: 'HTTP (HTTPS Only: false)'
Jobs using route 'blue.example.com':
╭─────────────┬──────────────────────┬────────╮
│ Name        │ Namespace            │ Weight │
├─────────────┼──────────────────────┼────────┤
│ hello-blue  │ /sandbox/admin       │ auto   │
│ hello-green │ /sandbox/admin       │ 25.00  │
╰─────────────┴──────────────────────┴────────╯

The output indicates that hello-green is receiving some of the traffic and hello-blue is receiving the remainder. A route weight of "0" means that the designated app will receive all remaining traffic. Note that route weight does not equate to traffic percentage.

8) Test route weighting.

Go to the route web page and reload the page repeatedly. The app is load balanced so that some requests are routed to the hello-green application rather than hello-blue. On about the fourth or fifth page load, the output should display "Hello Universe" instead of "Hello World".

Adjust route weighting

9) Split the traffic between the green and blue apps.

apc route weight http://blue.example.com --app hello-green --weight 50
╭─────────────────────────────────────────────╮
│            Route Weight Settings            │
├───────────────────┬─────────────────────────┤
│         App Name: │ hello-green             │
│         App Port: │ (auto-detected)         │
│       Route Type: │ http                    │
│   Route Endpoint: │ http://blue.example.com │
│ New Route Weight: │ 50%                     │
╰───────────────────┴─────────────────────────╯

Is this correct? [Y/n]:
Updating weight of route to 50.00%... done
Success!

Test and verify results. With 50 weight, the traffic is split evenly between the two apps.

apc route show blue.example.com
Route Type: 'HTTP (HTTPS Only: false)'
Jobs using route 'blue.example.com':
╭─────────────┬──────────────────────┬────────╮
│ Name        │ Namespace            │ Weight │
├─────────────┼──────────────────────┼────────┤
│ hello-blue  │ /sandbox/admin       │ auto   │
│ hello-green │ /sandbox/admin       │ 50.00  │
╰─────────────┴──────────────────────┴────────╯

10) Increase further the traffic sent to hello-green.

apc route weight http://blue.example.com --app hello-green --weight 75

Test and verify the results. The hello-green version should receive a majority of the traffic.

apc route show blue.example.com
Route Type: 'HTTP (HTTPS Only: false)'
Jobs using route 'blue.example.com':
╭─────────────┬──────────────────────┬────────╮
│ Name        │ Namespace            │ Weight │
├─────────────┼──────────────────────┼────────┤
│ hello-blue  │ /sandbox/admin       │ auto   │
│ hello-green │ /sandbox/admin       │ 75.00  │
╰─────────────┴──────────────────────┴────────╯

11) Continue increasing traffic to hello-green until it is receiving all of the load.

apc route weight http://blue.example.com --app hello-green --weight 100

Test and verify the results. The hello-green version should receive all traffic.

apc route show blue.example.com
Route Type: 'HTTP (HTTPS Only: false)'
Jobs using route 'blue.example.com':
╭─────────────┬──────────────────────┬────────╮
│ Name        │ Namespace            │ Weight │
├─────────────┼──────────────────────┼────────┤
│ hello-blue  │ /sandbox/admin       │ auto   │
│ hello-green │ /sandbox/admin       │ 100.00 │
╰─────────────┴──────────────────────┴────────╯

12 Delete the route

Once you've increased the route weight to 100 for hello-green so that all traffic is directed to it, you can delete the blue.example.com route from the hello-blue app:

apc route delete http://blue.example.com --app hello-blue

The apc route show command should indicate that the route is now mapped to hello-green.

apc route show blue.example.com
Route Type: 'HTTP (HTTPS Only: false)'
Jobs using route 'blue.example.com':
╭─────────────┬──────────────────────┬────────╮
│ Name        │ Namespace            │ Weight │
├─────────────┼──────────────────────┼────────┤
│ hello-green │ /sandbox/admin       │ 100.00 │
╰─────────────┴──────────────────────┴────────╯