Move your first application to IBM Cloud private in three steps
What is IBM Cloud private
IBM Cloud private is the new IBM Cloud offering with focuses on managing cloud native workloads on customer premises, leveraging customer existing investment on infrastructure, middleware, DevOps, security with greater insight of workloads.
IBM Cloud private is built on open source technologies like Kubernetes and lots others, with many years of IBM’s experience of operating, running and scaling of cloud platforms from IaaS to PaaS and SaaS.
Warning: If this is the first time you hear Kubernetes that is not Jack Sparrow, the rest of this reading will be boring.
Find out more about IBM Cloud private from here: https://www.ibm.com/cloud-computing/products/ibm-cloud-private/.
A Simple Sample Application
The example We use here is based on a simple socket.io chat example from GitHub https://github.com/socketio/chat-example, which can run easily with nodejs in five seconds.
It was forked into GitHub https://github.com/ibm-cloud-private/chat-example.
There is a little change in the code that is whenever a chat message is sent, a random joke will be retrieved using a Node.js module one-liner-joke. If you don’t like the jokes(some are bad jokes even though I used tag “Intelligence”), just comment that line out in index.js.
My ICp environment is a simple one node with boot node, master node, proxy node, worker node all in one virtual machine.
The ICp environment has been configured with microservice builder and integrated with my github organization.
More about micro service builder from here: https://www.ibm.com/support/knowledgecenter/en/SS5PWC/pipeline.html.
Migrate Your Application to IBM Cloud private
Ask anyone how to put an elephant into a fridge, you might get this answer: open the fridge door, push the elephant in, close the fridge door. Haha, simple. This applies to migrating applications from cloud to cloud, too!
To move the application here(a standalone nodejs application, the elephant) into IBM Cloud private(a private cloud platform, the fridge), we will have to:
1. Package the application. That is to build the application into a docker image
2. Move the application. That is to automatically build the image and depoy into cloud
3. Close the front door. That is to expore the application as a service and secure that with your network policy.
Step 1: Package the application
To build the application into docker image, write a docker build file with instructions to copy the code and start the application. For the chat example, the docker build file is as below(https://github.com/ibm-cloud-private/chat-example/blob/master/Dockerfile):
COPY package.json .
RUN npm install
COPY . .
CMD [ “npm”, “start” ]
Step 2: Move the application
Here the application will be built automatically by microservice builder via jenkins. Jenkins get notice automatically by github webhook and execute the build pipeline.
The jenkins file is as simple as this(https://github.com/ibm-cloud-private/chat-example/blob/master/Jenkinsfile):
image = ‘chat-example’
Step 3: Close the front door
To deploy the application into IBM Cloud private, we write a Kubernetes deployment file. Again the deployment file will be executed by microservice builder automatically.
In the Kubernetes deployment files, there are three types of resources defined:
ingress resource to access the application from network; service definition for ingress resource to forward request to; deployment of pod to run the application in containers.
a. Here the chat example application does not have a url path, everything is root(/) based, so we have to rewrite target for ingress path.
b. The application is using websocket which requires an explicit declaration for the ingress rule to maintain the web socket connection.
The kubernetes deploy file(https://github.com/ibm-cloud-private/chat-example/blob/master/manifests/deploy.yaml) is as below:
— path: /chat-example
— path: /socket.io
— name: chat-port
— name: chat-example
— name: PORT
Once all of these are done, the application will be automatically built and deployed to IBM Cloud private, with url accessible from network.
In the lab environment the primary IP address for IBM Cloud private is 192.168.11.100, the service can be accessed from http://192.168.11.100/chat-example:
Now add this gitHub repository(https://github.com/ibm-cloud-private/chat-example.git) into your micro service build and see how it is deployed automatically in seconds. Have fun!