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.

Lab Environment
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):

FROM node

WORKDIR /usr/src/app

COPY package.json .

RUN npm install

COPY . .

EXPOSE 8080

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):
@Library(‘MicroserviceBuilder’) _
microserviceBuilderPipeline {
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.

Note: 
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:

— -
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
 name: chat-example-ingress
 annotations:
 ingress.kubernetes.io/rewrite-target: /
 nginx.org/websocket-services: “chat-example-service”
spec:
 rules:
 — http:
 paths:
 — path: /chat-example
 backend:
 serviceName: chat-example-service
 servicePort: 8080
 — -
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
 name: chat-example-ingress-socket
 annotations:
 nginx.org/websocket-services: “chat-example-service”
spec:
 rules:
 — http:
 paths:
 — path: /socket.io
 backend:
 serviceName: chat-example-service
 servicePort: 8080
 — -
apiVersion: v1
kind: Service

metadata:
 name: chat-example-service
 labels:
 app: chat-example
spec:
 type: LoadBalancer

ports:
 — name: chat-port
 port: 8080
 targetPort: 8080
 protocol: TCP

selector:
 app: chat-example
 — -
apiVersion: extensions/v1beta1
kind: Deployment

metadata:
 name: chat-example
 labels:
 app: chat-example

spec:
 replicas: 1
 selector:
 matchLabels:
 app: chat-example

template:
 metadata:
 labels:
 app: chat-example

spec:
 containers:
 — name: chat-example
 image: chat-example:latest
 imagePullPolicy: IfNotPresent

readinessProbe:
 tcpSocket:
 port: 8080
 env:
 — name: PORT
 value: “8080”

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!

Orginally posted here: https://www.ibm.com/developerworks/community/blogs/0a5d255b-7876-4b55-9c7c-1d2f46de4ff4/entry/Move_your_first_application_to_IBM_Cloud_private?lang=en.

Like what you read? Give Jacky Huang a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.