How to migrate from one Cloud Foundry Stack to another Stack
search cancel

How to migrate from one Cloud Foundry Stack to another Stack

book

Article ID: 297714

calendar_today

Updated On:

Products

VMware Tanzu Application Service for VMs

Issue/Introduction

This article walks you through the ways to migrate from one stack to another in Pivotal Cloud Foundry (PCF).

Environment


Resolution

Push Your App

The easiest way to update your stack is to do a `cf push`. You can set the `cf push -s <stack>` flag or set `stack: <stack>` in your application.yml file and it will set a specific stack for your application to use.

For example: `cf push -s cflinuxfs3 my-cool-app`

The push executes, updates the stack being used, re-stages your application using the new stack, and when the app starts, it will be running on the new stack.

Note: Please keep in mind that doing a `cf push` can result in downtime for your app. The app is stopped before it is restaged. The period of time between your app staging and starting will be downtime. It is recommended that you do a blue/green deploy if you need to avoid downtime for your application.


Use the Stack Auditor plugin

There is a cf CLI plugin called Stack Auditor which can be used to:

  • Check for applications that need to switch stacks
  • Switch the necessary applications between stacks

This is an excellent option if you do not want to perform a  `cf push` for reasons such as:

  • You do not have your application code at the moment
  • You have many apps that need to be migrated to a new stack

Instructions for installing the plugin can be found here. Basic usage instructions for the plugin can be found here.

To list apps and their stacks, execute the following cf command: 

$ cf audit-stack
Retrieving stack information for all apps...

cf-support/aarif/FTServiceCore cflinuxfs2
cf-support/aarif/anser-app-02 cflinuxfs2
cf-support/aarif/anser-php-app-03 cflinuxfs2
cf-support/aarif/directory-service-anser cflinuxfs2
...

To switch an app's stack, execute the following cf command: 

$  cf change-stack nginxappy cflinuxfs3
Attempting to change stack to cflinuxfs3 for acceptance/nginxappy/...
Restarting nginxappy with down time...
Restoring prior application state: STARTED
Application nginxappy was successfully changed to Stack cflinuxfs3

Please keep in mind that running `cf change-stack` will re-stage your app.

As mentioned above, this can cause downtime. The change-stack command runs two logical steps.

  • The first is the attempt to restage the app onto cflinuxfs3. If this fails, it backs out and the cflinuxfs2 app remains running with zero downtime.
  • If the staging is successful, at this point, the cflinuxfs2 app is brought down while the app on cflinuxfs3 starts up. If startup fails during the change-stack command, we point back to the cflinuxfs2 app and start it back up.

Please perform a blue/green deployment  instead of using `cf change-stack` if downtime is unacceptable for your application.

The change-stack command also supports a --v3 flag. The --v3 flag will make use of the CAPI zero downtime endpoints, resulting in a true zero-downtime migration.

Note: This flag is only applicable for PWS or Open Source installations of Cloud Foundry. This should not be used with PAS versions 2.3 or 2.4, as it will lead to unexpected behavior.

$cf change-stack nginxappy cflinuxfs3 --v3
Attempting to change stack to cflinuxfs3 for acceptance/nginxappy/...

Restarting nginxappy with zero down time...
Restoring prior application state: STARTED
Application nginxappy was successfully changed to Stack cflinuxfs3



Additional Information

Here are some additional useful commands:
  • By default, `cf audit-stack` shows all the apps in all the orgs and spaces where you have visibility, including those already running `cflinuxfs3` or even Windows stacks. To find all of the apps that need to be migrated from a specific stack, like `cflinuxfs2` run `cf audit-stack | grep 'cflinuxfs2'`.
  • To find apps that are in a specific org, you can run `cf audit-stack | grep -e '^<org-name>'`, where `<org-name>` is the desired org name.
  • If you'd like to get a list of just the app names, you can run `cf audit-stack | awk -F '[/ ]' '{ print $3 }'. If you'd like other information, you can use $1 which is the org, $2 which is the space, $3 which is the app and $4 which is the stack.
Lastly, here is an example that pull all of the suggestions above together. This will generate a script that can be run to go through and update the stack for all `cflinuxfs2` apps in an specific org (remember this will incur downtime for each app):
cf audit-stack | grep 'cflinuxfs2' | grep -e '^<org-name>' | awk -F '[/ ]' '{ print "cf t -o \""$1"\" -s \""$2"\"\ncf change-stack "$3" cflinuxfs3" }' > update-stack.sh
To actually make the change, run the script: `bash update-stack.sh`.