Create a Blue/Green PCF Deployment

Updated 1 month ago by Chakravarthy Tenneti

Harness PCF Blue/Green deployments use the route(s) in the PCF manifest.yml and a temporary route you specify in the Harness Workflow.

The Workflow deploys the app using the temporary route first using the App Setup command. Next, in the App Resize command, Harness maintains the number of instances at 100% of the instances specified in the manifest.yml.

For Blue/Green deployments, the App Resize step is always 100% because it does not change the number of instances as it did in the Canary deployment. In Blue/Green, you are simply deploying the new app to the number of instances set in the App Setup step and keeping the old app at the same number of instances (100% count).

Once that deployment is successful, the Workflow Swap Routes command switches the networking routing, directing production traffic (Green) to the new app and stage traffic (Blue) to the old app.

In this topic:

Before You Begin

Visual Summary

Here's the output after a successful Blue/Green PCF Deployment.

Step 1: Specify the PCF Service Routes

In the manifest.yml in your Harness PCF Service, you can specify the route(s) to use for the Blue/Green deployment. For example:

  ...
routes:
- route: example.com

Each route for the app is created if it does not already exist.

As you will see when you set up the Blue/Green Workflow, you specify a temporary route in the App Setup command's Temporary Routes setting:

Step 2: Set Up a PCF Blue/Green Workflow

To explain PCF Blue/Green Workflow commands and settings, we will create a Blue/Green Workflow that uses a temporary route and, if it is successful, deploys 100% of instances using the primary route.

To implement this Blue/Green Workflow, do the following:

  1. In your Harness Application, click Workflows.
  2. In Workflows, click Add Workflow. The Workflow dialog appears.
  3. In Name, enter a name for the Workflow.
  4. In Workflow Type, select Blue/Green Deployment.
  5. In Environment, select the Environment you created for PCF.
  6. In Service, select a Harness PCF Service you have created. The Service manifest.yml must contain a route. The route can be an existing route or not. If the doesn't exist, Harness will create it for you. This is the route that will be used at the final stage of the Blue/Green deployment. The temporary route for the prior stage will be selected in the App Setup step of Workflow.
  7. In Infrastructure Definition, select the Infrastructure Definition that describes the target PCF space.

    When you are done, the dialog will look something like this:
  8. Click Submit.

The new Blue/Green Workflow is displayed, along with the preconfigured steps:

Step 3: App Setup

Click App Setup to see the default, preconfigured command:

None of the settings in this dialog are mandatory, but for Blue/Green Workflows, the Match running instances, Additional Routes, and Temporary Routes settings are important.

If you select Match running instances, Harness will ignore the number of instances set in the Service's manifest.yml instances property and use the number of currently running instances as the desired instance count during deployment.

The first time you deploy this Workflow, there is no reason to select Match running instances as there are no current running instances.

Additional Routes is automatically populated with the routes Harness can find using the Infrastructure Definition you selected for this Workflow

Additional Routes has two uses in Blue/Green deployments:

  • Select the routes that you want mapped to the app in addition to the routes already mapped in the app in the manifest in your Harness Service.
  • You can also omit routes in the manifest in your Harness Service, and simply select them in Additional Routes. The routes selected in Additional Routes will be used as the final (green) routes for the app.

Temporary Routes is automatically populated with the routes Harness can find using the Infrastructure Definition you selected for this Workflow.

In Temporary Routes, you can select one or more temporary routes for Harness to use when it creates the PCF app. Later, in the Swap State step, Harness will replace these routes with the routes in the manifest.yml routes property in your Service.

If you do not select a route in Temporary Routes, Harness will create one automatically.

For information on using the Use App Autoscaler Plugin settings, see Use the App Autoscaler Service.

Step 4: App Resize

Click App Resize to see the default settings.

For Blue/Green deployments, the App Resize step is always 100% because it does not change the number of instances as it did in the Canary deployment. In Blue/Green, you are simply deploying the new app to the number of instances set in the App Setup step and keeping the old app at the same number of instances.

Step 5: Verify Staging

There are no commands in Verify Staging because you have not set up verification steps in this tutorial, and you would not add them in the initial deployment because there are no other deployments for the steps to use in comparison.

Later, when you are developing Blue/Green Workflows, add verification steps to verify the deployment of your app using the temporary route(s). This way, Harness will only proceed to the Swap Routes step if verification does not detects failures. For more information about verifying deployments, see Continuous Verification.

Step 6: Swap Routes

The final step in the PCF Blue/Green Workflow is the Swap Routes command.

This command will swap the route(s) used by the deployed app from the temporary route(s) to the route(s) specified in the manifest.yml in your Service.

When Swap Routes is used in a Workflow's Rollback Steps, the app that was active before deployment is restored to its original state with the same instances and routes it had before deployment. The new app is left with the temporary route set in App Setup with 0 instances so you can troubleshoot it.

Step 7: Deploy a PCF Blue/Green Workflow

Now that the Blue/Green Workflow is configured, from the breadcrumb menu, click back to the main Workflow page.

You can now deploy the Blue/Green Workflow.

  1. Click Deploy.
  2. In Start New Deployment, select an artifact to deploy, and click Submit.

The PCF Blue/Green Workflow deploys.

Here you can see the App Step command deployed:

When this step is deployed, the output will look something like this:

---------- Starting PCF App Setup Command

# Fetching all existing applications
# Existing applications:
ExampleForDoc__PCF__Blue__Green__Staging__2

# Processing Apps with Non-Zero Instances
# No Change For Most Recent Application: ExampleForDoc__PCF__Blue__Green__Staging__2

# No applications were eligible for deletion

# Creating new Application
# Manifest File Content:
---
applications:
- name: ExampleForDoc__PCF__Blue__Green__Staging__3
memory: ((PCF_APP_MEMORY))
instances: 0
path: /home/ubuntu/harness-delegate/./repository/pcfartifacts/11uZOBMRQoSbDqr_WfRuaQ/1572474750133SampleWebApp.war
random-route: true


# CF_HOME value: /home/ubuntu/harness-delegate/./repository/pcfartifacts/11uZOBMRQoSbDqr_WfRuaQ
# Performing "login"
API endpoint: api.run.pivotal.io
Authenticating...
OK

Targeted org Harness
Targeted space AD00001863
...
Getting app info...
Creating app with these attributes...
+ name: ExampleForDoc__PCF__Blue__Green__Staging__3
path: /home/ubuntu/harness-delegate/repository/pcfartifacts/11uZOBMRQoSbDqr_WfRuaQ/1572474750133SampleWebApp.war
+ instances: 0
+ memory: 350M
routes:
+ examplefordocpcfbluegreenstaging3-insightful-cat.cfapps.io
...
# Application created successfully
# App Details:
NAME: ExampleForDoc__PCF__Blue__Green__Staging__3
INSTANCE-COUNT: 0
ROUTES: [examplefordocpcfbluegreenstaging3-insightful-cat.cfapps.io]

---------- PCF Setup process completed successfully
# Deleting any temporary files created

The route specified in the Service manifest.yml is docs.cfapps.io:

Note that in the App Setup step, a temporary route has been used: examplefordocpcfbluegreenstaging3-insightful-cat.cfapps.io.

Here you can see the App Resize command deployed:

When this step is deployed, the output will look something like this:

---------- Starting PCF Resize Command

# Upsizing new application:
APPLICATION-NAME: ExampleForDoc__PCF__Blue__Green__Staging__3
CURRENT-INSTANCE-COUNT: 0
DESIRED-INSTANCE-COUNT: 6
# Application upsized successfully

# Application state details after upsize:
NAME: ExampleForDoc__PCF__Blue__Green__Staging__3
INSTANCE-COUNT: 6
ROUTES: [examplefordocpcfbluegreenstaging3-insightful-cat.cfapps.io]

Instance Details:
Index: 0
State: STARTING
Disk Usage: 0
CPU: 0.0
Memory Usage: 0

Index: 1
State: STARTING
Disk Usage: 0
CPU: 0.0
Memory Usage: 0

Index: 2
State: STARTING
Disk Usage: 0
CPU: 0.0
Memory Usage: 0

Index: 3
State: STARTING
Disk Usage: 0
CPU: 0.0
Memory Usage: 0

Index: 4
State: STARTING
Disk Usage: 0
CPU: 0.0
Memory Usage: 0

Index: 5
State: STARTING
Disk Usage: 0
CPU: 0.0
Memory Usage: 0

# BG Deployment. Old Application will not be downsized.
--------- PCF Resize completed successfully

Note that 100% of the instances specified in the Service manifest.yml have been deployed (6).

Here you can see the Swap Routes command deployed:

When this step is deployed, the output will look something like this:

--------- Starting PCF Route Update

# Adding Routes
APPLICATION: ExampleForDoc__PCF__Blue__Green__Staging__3
ROUTE:
[
docs.cfapps.io
]

# Unmapping Routes
APPLICATION: ExampleForDoc__PCF__Blue__Green__Staging__3
ROUTES:
[
examplefordocpcfbluegreenstaging3-insightful-cat.cfapps.io
]
# Unmapping Routes was successfully completed

# Adding Routes
APPLICATION: ExampleForDoc__PCF__Blue__Green__Staging__2
ROUTE:
[
examplefordocpcfbluegreenstaging3-insightful-cat.cfapps.io
]

# Unmapping Routes
APPLICATION: ExampleForDoc__PCF__Blue__Green__Staging__2
ROUTES:
[
docs.cfapps.io
]
# Unmapping Routes was successfully completed

--------- PCF Route Update completed successfully

Note how the new app receives the docs.cfapps.io route from the Service manifest.yml and the old route receives the temporary route examplefordocpcfbluegreenstaging3-insightful-cat.cfapps.io.

The Blue/Green deployment is complete.

Next Steps


How did we do?