March 2, 2020 By Takeyuki Nakajo 5 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)

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.
  3. 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.
  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.
  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.
  9. 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.
  2. 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.
  4. 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.
    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.
  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.
  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.
  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>.
  10. 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.

Was this article helpful?
YesNo

More from Cloud

IBM Tech Now: April 8, 2024

< 1 min read - ​Welcome IBM Tech Now, our video web series featuring the latest and greatest news and announcements in the world of technology. Make sure you subscribe to our YouTube channel to be notified every time a new IBM Tech Now video is published. IBM Tech Now: Episode 96 On this episode, we're covering the following topics: IBM Cloud Logs A collaboration with IBM watsonx.ai and Anaconda IBM offerings in the G2 Spring Reports Stay plugged in You can check out the…

The advantages and disadvantages of private cloud 

6 min read - The popularity of private cloud is growing, primarily driven by the need for greater data security. Across industries like education, retail and government, organizations are choosing private cloud settings to conduct business use cases involving workloads with sensitive information and to comply with data privacy and compliance needs. In a report from Technavio (link resides outside ibm.com), the private cloud services market size is estimated to grow at a CAGR of 26.71% between 2023 and 2028, and it is forecast to increase by…

Optimize observability with IBM Cloud Logs to help improve infrastructure and app performance

5 min read - There is a dilemma facing infrastructure and app performance—as workloads generate an expanding amount of observability data, it puts increased pressure on collection tool abilities to process it all. The resulting data stress becomes expensive to manage and makes it harder to obtain actionable insights from the data itself, making it harder to have fast, effective, and cost-efficient performance management. A recent IDC study found that 57% of large enterprises are either collecting too much or too little observability data.…

IBM Newsletters

Get our newsletters and topic updates that deliver the latest thought leadership and insights on emerging trends.
Subscribe now More newsletters