How to Migrate Cloud Foundry Applications to Docker Containers on a Kubernetes Cluster

4 min read

By following three easy steps, you'll learn how to migrate your Cloud Foundry applications to Docker containers on IBM Cloud Kubernetes Service.

The IBM Cloud Kubernetes Service delivers powerful tools by combining Docker containers, the Kubernetes technology, an intuitive user experience, and built-in security and isolation to automate the deployment, operation, scaling, and monitoring of containerized apps in a cluster of compute hosts. 

If you have any Cloud Foundry applications, you can migrate them to Docker containers on the IBM Cloud Kubernetes Service. There are many ways to do this, but I'm going to show you the simplest way by using the IBM Cloud Continuous Delivery service.

Prerequisites

Steps

  1. Prepare the source code for a Cloud Foundry application.
  2. Create a new toolchain for deploying a Kubernetes app.
  3. Configure the Delivery Pipeline for deploying a Kubernetes app.

1. Prepare the source code for a Cloud Foundry application

This is the sample Cloud Foundry application running on the IBM public cloud. For this tutorial, you can use the the Node.js Hello World sample source code.

When you have your source code, it should look like this:

  • GitHub repository URL: https://github.com/(account)/(project)
  • GitLab repository URL: https://us-south.git.cloud.ibm.com/(account)/(project)
This is the sample Cloud Foundry application running on the IBM public cloud. For this tutorial, you can use the the Node.js Hello World sample source code.

2. Create a new toolchain for deploying a Kubernetes app

The IBM Cloud Continuous Delivery service includes open toolchains that automate the building and deployment of applications. You will need to create a new toolchain to deploy a Kubernetes app with the source code.

  1. From the IBM Cloud console, click the Menu icon and select DevOps.
  2. On the DevOps dashboard, on the Toolchains page, click Create a Toolchain.
    On the DevOps dashboard, on the Toolchains page, click Create a Toolchain.
  3. On the Create a Toolchain page, click the toolchain template Develop a Kubernetes app.
    On the Create a Toolchain page, click the toolchain template Develop a Kubernetes app.
  4. On the Develop a Kubernetes app page, type in the Toolchain Name.
    hw
  5. In the Tool Integrations section, select the Repository type (Clone), enter the Source repository URL (https://cloud.ibm.com/conapi/template/nodejsHelloWorld/download/starter_code), and type a new Repository Name. This indicates the source repository is cloned into your source repository. If you want, you can type the source repository URL for your Cloud Foundry app.
    In the Tool Integrations section, select the Repository type (Clone), enter the Source repository URL
  6. In the Tool Integrations section, click Delivery Pipeline, put in the App name, and type the existing IBM Cloud API key or click the New button to create a new key. 
  7. Enter the Container registry region and Container registry namespace where the Docker image is stored.
  8. Select the Cluster region, Resource Group, Cluster name, and Cluster namespace where the app is deployed.
    Select the Cluster region, Resource Group, Cluster name, and Cluster namespace where the app is deployed.
  9. Confirm your updates by clicking Create
    Confirm your updates by clicking Create. 

Several steps will run automatically to set up your toolchain.

  • The toolchain is created.
  • The source repository is cloned into your source repository.
  • The delivery pipelines are created and triggered.

3. Configure the delivery pipeline for deploying a Kubernetes app

  1. Once the toolchain is created, your toolchain Overview is displayed. Click the Delivery Pipeline panel to access the delivery pipeline stages (BUILD, CONTAINERIZE, and DEPLOY). Let's see if a Kubernetes app deployed.
    Once the toolchain is created, your toolchain Overview is displayed. Click the Delivery Pipeline panel to access the delivery pipeline stages (BUILD, CONTAINERIZE, and DEPLOY). Let's see if a Kubernetes app deployed.
  2. Wait a sec! You see that the Check dockerfile job failed in the CONTAINERIZE stage. Click the job to see the log.
    Wait a sec! You see that the Check dockerfile job failed in the CONTAINERIZE stage. Click the job to see the log.
  3. This is because a file named Dockerfile was not found in the source repository. Dockerfile is the instruction to build a Docker image automatically, and you just need to add a Dockerfile by following the instructions here.
    This is because a file named Dockerfile was not found in the source repository. Dockerfile is the instruction to build a Docker image automatically, and you just need to add a Dockerfile by following the instructions here.
  4. Go back to the Toolchain page and click the Git panel to access your source code in the repository. 
    Go back to the Toolchain page and click the Git panel to access your source code in the repository. 
  5. Add a new file named Dockerfile, copy the following code, and paste it into the file. Then click Commit.
    Add a new file named Dockerfile, copy the following code, and paste it into the file. Then click Commit.
    FROM node:alpine
    RUN apk update && apk upgrade
    # Install the application
    ADD package.json /app/package.json
    RUN cd /app && npm install
    COPY app.js /app/app.js
    RUN mkdir /app/public
    COPY /public/ /app/public/
    WORKDIR /app
    ENV PORT 8080
    EXPOSE 8080
    # Define command to run the application when the container starts
    CMD ["node", "app.js"]
    FROM node:alpine RUN apk update && apk upgrade # Install the application ADD package.json /app/package.json RUN cd /app && npm install COPY app.js /app/app.js RUN mkdir /app/public COPY /public/ /app/public/ WORKDIR /app ENV PORT 8080 EXPOSE 8080 # Define command to run the application when the container starts CMD ["node", "app.js"]
  6. Go back to the Toolchain page, click the Delivery Pipeline panel to access the delivery pipeline stages.
    Go back to the Toolchain page, click the Delivery Pipeline panel to access the delivery pipeline stages.
  7. Because you committed the change in the source repository, it triggered to run the Delivery Pipeline. After about 10 minutes, you will see that all pipeline stages (BUILD, CONTAINERIZE, and DEPLOY) passed. Click the Deploy to Kubernetes job in the DEPLOY stage to see the Stage History.
    Because you committed the change in the source repository, it triggered to run the Delivery Pipeline. After about 10 minutes, you will see that all pipeline stages (BUILD, CONTAINERIZE, and DEPLOY) passed. Click the Deploy to Kubernetes job in the DEPLOY stage to see the Stage History.
    Because you committed the change in the source repository, it triggered to run the Delivery Pipeline. After about 10 minutes, you will see that all pipeline stages (BUILD, CONTAINERIZE, and DEPLOY) passed. Click the Deploy to Kubernetes job in the DEPLOY stage to see the Stage History.
  8. As you can see from the Stage History for the Deploy to Kubernetes Job in the DEPLOY stage, the initial deployment.yaml is automatically created because there is no deployment.yaml in the source repository. You can create a deployment.yaml file in the source repository to define how you deploy apps to containers on the Kubernetes cluster and add it in the repository for your requirement. See more details here.
    As you can see from the Stage History for the Deploy to Kubernetes Job in the DEPLOY stage, the initial deployment.yaml is automatically created because there is no deployment.yaml in the source repository.
  9. You will see the message Finished: SUCCESS in the DEPLOY stage. Click the VIEW THE APPLICATION AT: http://184.172.250.48:30001/. The app is exposed with a NodePort service in the format http://<IP_address>:<nodeport>.
    You will see the message Finished: SUCCESS in the DEPLOY stage. Click the VIEW THE APPLICATION AT: http://184.172.250.48:30001/. The app is exposed with a NodePort service in the format http://<IP_address>:<nodeport>.
  10. The application is successfully deployed as a Kubernetes app. You're now able to access the application running on the Kubernetes service.
    The application is successfully deployed as a Kubernetes app. You're now able to access the application running on the Kubernetes service.

Summary

By following these steps, you're now able to migrate Cloud Foundry applications to Docker containers on IBM Cloud Kubernetes Service. In doing so, you expose the app with a NodePort service in the format http://<IP_address>:<nodeport>

If you use a standard cluster, you can create the ingress resource to route traffic to your app service so that you can expose apps with the IBM-provided domain or a custom domain—also HTTPS and TLS/SSL authentication in the format https://<yourcustom.domain.net>. Learn more about the ingress resource.

Be the first to hear about news, product updates, and innovation from IBM Cloud