Migrate and deploy Cloud Foundry applications to Kubernetes

Transform a Cloud Foundry application to Kubernetes with the Move2Kube command-line tool. You’ll learn how to create deployment artifacts using Move2Kube’s three-step process: collect, plan, and transform.

Move2Kube is a tool that helps automate your migration to Kubernetes from platforms like Cloud Foundry or Docker Compose. It analyzes source files, such as manifest files, and generates the deployment artifacts required to deploy the application in Kubernetes.

Prerequisites:


Move2Kube is a tool that helps automate your migration to Kubernetes from platforms like Cloud Foundry or Docker Compose. It analyzes source files, such as manifest files, and generates the deployment artifacts required to deploy the application in Kubernetes.

To transform a Cloud Foundry application to Kubernetes, simply execute the following command:

$ move2kube transform -s cloud-foundry

Move2Kube will automatically analyze the artifacts in the cloud-foundry directory and transform and create all artifacts required for deploying the application in Kubernetes.

Create a source code directory

First, you will need a directory that contains the source code files and the manifest.yml file of a Cloud Foundry application. 

  1. In this learning path, we will use the cloud-foundry sample directory from the move2kube-demos repository:

    $ curl https://move2kube.konveyor.io/scripts/download.sh | bash -s -- -d samples/cloud-foundry -r move2kube-demos
  2. Let's see the structure inside the ./cloud-foundry directory. The cloud-foundry directory contains the source code files and the manifest.yml file:

    $ tree cloud-foundry
    
    cloud-foundry/
    
      ├── cfnodejsapp
    
      │   ├── main.js
    
      │   ├── manifest.yml
    
      │   ├── package-lock.json
    
      │   └── package.json
    
      └── m2k_collect
    
       └── cf
    
           └── cfapps.yaml
  3. Next, install the following tools:
  4. To verify that dependencies were installed correctly, you can run any of the following commands:
    • $ move2kube version
    • $ docker version
    • $ podman info
    • $ kubectl version
  5. Finally, install the Cloud Foundry CLI.

The example application

To demonstrate how to migrate a Cloud Foundry application to Kubernetes with Move2Kube, we will use the source code inside the cloud-foundry/cfnodejsapp directory. 

If you want to try out Move2Kube on your Cloud Foundry application, then in place of our sample cloud-foundry directory, provide the path of the source directory (containing the source code and/or manifest files) of your Cloud Foundry application to Move2Kube during the plan phase.

Deploy to Cloud Foundry

Optional step: Here we will deploy a simple Node.js application into Cloud Foundry. If you already have a running Cloud Foundry application, you can use that instead. 

  1. Provision a Cloud Foundry app with the name cfnodejsapp using your cloud provider (e.g., IBM Cloud). 
  2. Make note of the API endpoint. (You can find a list of supported API endpoints for the IBM Cloud Foundry service in the documentation).
  3. Log in to Cloud Foundry using the following command:

    $ cf login -a <YOUR CF API endpoint>
  4. Run the following commands to deploy the sample application to Cloud Foundry. The sample application’s source code is present inside the ./cloud-foundry/cfnodejsapp folder.

    $ cf push -f ./cloud-foundry/cfnodejsapp -p ./cloud-foundry/cfnodejsapp

You can visit the URL of the application (you can get this by running cf apps) to see it running.

Generate target artifacts

Now that we have a running Cloud Foundry application, we can transform it using Move2Kube. We will use a three-stage process (collect, plan, and transform) for the transformation. Be sure to run these steps from the directory where the cloud-foundry directory is located.

Collect your data

We will first collect some data about our running Cloud Foundry application.

Note: This step is only necessary if you are interested in metadata such as environment variables from a running instance. If you don't have a running application, you can use the m2k_collect directory that comes with the sample.

  1. Here we will limit the collection to only Cloud Foundry information using the -a cf annotation flag:

    $ cf login -a <YOUR CF API endpoint>
    $ move2kube collect -a cf
    INFO[0000] Begin collection  
    INFO[0000] [*collector.CfAppsCollector] Begin collection 
    INFO[0013] [*collector.CfAppsCollector] Done 
    INFO[0013] [*collector.CfServicesCollector] Begin collection 
    INFO[0027] [*collector.CfServicesCollector] Done  
    INFO[0027] Collection done
    INFO[0027] Collect Output in [/Users/username/m2k_collect]. Copy this directory into the source directory to be used for planning.
  2. The data we collect will be stored in a new directory called ./m2k_collect.

    $ ls m2k_collect
    cf
  3. The ./m2k_collect/cf directory contains a YAML file with runtime information about the application you are transforming. The file contains details about the supported buildpacks, the memory, the number of instances, and the supported ports. If there are environment variables, it collects that information, too.
  4. Move the ./m2k_collect/cf directory into the source directory ./cloud-foundry:
  5. $ mv m2k_collect cloud-foundry/
Previous resource
Overview: Migrate and deploy Cloud Foundry applications to Kubernetes
Next resource
Plan and transform your application