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.
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:
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.
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 (link resides outside ibm.com).
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 (link resides outside ibm.com).
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.
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.