Running a Microservice containers on Kubernetes straight from a Github repo

This blogpost is about my experience of deploying a container in a Cloud on a Kubernetes cluster with Red Hat OpenShift directly from your Github repo from CLI. Now it is possible to use Red Hat OpenShift v4.3 on IBM Cloud. You will find all the needed steps below. If you like it the idea — read on!

Please note that at the moment of writing this post the Red Hat OpenShift 4.3 is in Beta on IBM Cloud for couple of days more — so the Red Hat OpenShift license fee is waved 👋 and we can enjoy the OpenShift only by paying for the bare metal Kubernetes nodes!

Step 1 — access the cloud

So you are interested to deploy your microservice as a container on Kubernetes cluster straight from a Github repo. In this blog post you will see how to deploy a container on Kubernetes based on Red Hat OpenShift. First, you need to start with a free of charge IBM Cloud account here (it is called LITE account — and this URL to gives an author = me — some brownie points):

Step 2 — provision a cluster

To provision a single node of Kubernetes — you can do it for free in IBM Cloud (but you need to upgrade to the Pay-Go account) the only caveat is that you would need to rebuild your cluster after 21 days.

Yet for this particular functionality and the example below I chose Kubernetes clusters based on the Red Hat OpenShift. Specifically the Red Hat OpenShift version 4.3. I spun a cluster of 3 nodes (4vCPUs each and 16GB RAM = 3x4x16) — note that you might be still eligible for the BETA promotion — just make sure the v3.5 are still in Beta, so you won’t need to pay the monthly license fee upfront, only the bare metal fees — and these can be tuned to hourily usage.

Step 3 — access the cluster from CLI 💻

Previously I published on how to create a container from an image from the Image Repository using UI 🖥. You can also do it from the Command Line Interface aka CLI. Simply get the token to your cluster and use it in Web Shell environment. Now you can point to the github repository of your choice. I did it the following way. So we are using our CLI — start with opening your terminal.

HINT! Alternatively you can use the Cloud Shell — in the browser terminal. Open it from the cluster view page. This almost all having installed terminal opens for you and without downloading anything to your local station you can run various cloud and cluster operations including Red Hat OpenShift.

Below steps are showing the use of the IBM Cloud Shell, since it is easier to accomplish (you can go ahead to use your local machine as well, if that is better suited for your particular use case, don’t forget to install Red Hat OpenShift CLI ”oc”).

Your terminal is getting provisioned

You can now open the Cloud Shell terminal and use the oc token command (the oc CLI pre-installed!) — in my example I am running servers out from Sweden 🇸🇪 :

oc login --token=some-token-here --server=

The above command allowed you to access the cluster.

Here comes the oc login with edited out token information

You can simply check all the projects. Just write:

oc projects
The results of the oc projects command

Step 4 — create a new project

Let’s start by creating the dedicated project for our application from GitHub repo. Let’s call the project my-github-based-app:

oc new-project my-github-based-app

Now lets get the OpenShift to fetch the GitHub source and deploy it in our project.

Step 5 — deploy your container straight from a github repo

You can create a new app called here authors-git from the subdirectory “deploying-to-openshift” of the GitHub repo:

oc new-app --context-dir=deploying-to-openshift --name=authors-git
The results of the oc new-project and oc new-app commands

You can now view the builds in the Web Console of Red Hat OpenShift— and your app will be shown there:

You can also find the status of the app from CLI:

oc status

Step 6 — create a route to your containerized app

Now we can create the routes, since as you can see the pod and the dedicated service are deployed already.

oc expose svc/authors-git

and what is the route?

oc get route/authors-git

You should receive a route URL like this one:

You can also see it at the Web Console of Red Hat OpenShift:

Now add the /openapi/ui to the end of the route URL, like this:

And now you are ready to access the application. That was really fast, wasn’t it!?

So to test it type in the browser the above address with trailing /openapi/ui as shown above… and do couple clicks as shown below.

Make sure you are adding /openapi/ui at the end of your route URL
The microservice shows its parameters
You can try it out!
Hit “Execute” to see the results
Et voila — the results!

You can check the full github repository on the given example — the source code, and other ways of deployment with APEX legendswritten by Niklas Heidloff with his friends here:
If you like this short blogpost — please subscribe to my twitter account:

I am a technology advocate for autonomous robots, AI, mobile and Internet of Things - with a view from both the enterprise and a robotics startup founder.