Deploy a Spring Boot Application on OpenShift 3.11

In my previous post, I described the method and procedure for running an OpenShift 3.11 locally on VirtualBox Machine using a Vagrant tool. In today’s post, I would like to take one step further to describe the procedure about deploying Spring Boot Application on OpenShift 3.11. As I had already explained in my earlier post about Spring Boot and Maven, I am not going to discuss much about it in this post. So, Let ‘s concentrate only on commands to use for Deploying Application on OpenShift. Deployment can be done either on the “oc” command line tool or creating the deployment in “yaml” or “json” file.  Since we have just started learning OpenShift in my blog, it is better to learn to start initially with the “oc” command line tool for deploying the application.

We had enough much talked about “oc” command line tools. Let’s start exploring the deployment on OpenShift. To get started, we need the following prerequisites.


  • oc binary tool
  • VirtualBox
  • Vagrant
  • Basic Linux Commands
  • Postman / curl

Bringing up OKD 3.11 on VirtualBox VM

To bring up OpenShift 3.11 ( a.k.a OKD) on VirtualBox VM, First off, you need to set up the VirtualBox and Vagrant tool in your local machine. If you are new to VirtualBox and Vagrant setup on Linux, I would recommend reading my earlier post. Once the VirtualBox and Vagrant setup is done, you can run “vagrant up” command to bring up the VM and run “vagrant ssh” to login.

Cool!. VirtualBox VM is up and running. Next step to bring up OpenShift Cluster by running “oc cluster up” command. Ensure that okd binary is downloaded and extracted locally before running “oc” command. If the command is successful, you are able to see the below output as below.

In order to gain admin privileges for OpenShift, run the below command.

I successfully logged in as system admin and am able to see all the Projects.  Each project considers as dedicated space for running the application. The symbol “*” indicates before myproject namespace indicates that user admin has access to create, delete and update resources on the particular project.  In case, you like to know the resources what is running on other namespaces, you may need to use a command as  ‘oc project <projectname>’  or “oc get projects –all-namespaces”

Building  Spring Boot Application

So far, we have learned how to bring up OKD on VirtualBox VM. Now, Let’s start learning on Building and Deploying the Spring Boot application on OpenShift. Before starting that we need a JDK image to run a java application. Hence, Ensure that JDK image is available in Openshift project. In case you don’t find an imagestream for OpenJDK, you will have to import the image manually. ImageStream is one of the OpenShift feature which will allow you to download and maintain the images in the registry.  If you are not clear about ImageStream, I will cover in another blog in details.  Let’s start running “oc get istag” command to check OpenJDK image is available in openshift project.

The above output confirms that the OpenJDK image is available in Openshift Project. So, Next step will be creating Buildconfig and ImageStream using “oc new-build” command.  One more thing, you need a source code to build an application. So, you can download the source code from my github repository.

In order to confirm that BuildConfig is created, you can run the below command to verify.

In case you are interested to know what BuildConfig configuration is all about. Run “oc get bc springboot-demo -o yaml” command and see the output.

Now! we need to build our spring boot application to create an image. The command “oc start-build” basically compile a source code using S2I command and build an image. This compilation process is called as source-to-image. You may ask where this s2i command stores and how it is triggering a maven build. s2i command and maven command are built inside OpenJDK8 image. For more details, you can run a JDK image as a container and “rsh to the pod”.  Let’s run “oc start-build” command to trigger a Build and Compile process.

Since the Build process output is lengthy, I have cut down the displayed output and pasted here. If the source code compilation process is successful, you would be able to see the image is pushing to docker registry at the end of the command output.

The display below command confirms that spring boot image is pushed and the image stream is created successfully.

The command “oc new-app” will be creating a deployment , ImageStream, and route for spring boot application.

To check the status of OpenShift deployment, run “oc status” command.

Cool! Resources are up and running. Wait, we are still pending with creating a route for this application. The route is nothing but an ingress controller which is customized in a way to externalize the application to the outside world in the form of API Gateway using HaProxy application.

In order to expose a service in the command line, run the below command.

Finally, let’s post some value and try to get the same result as written in the java code.


So far, we have learned how to deploy an application in OpenShift using “oc” command line tool. In the upcoming blog, we will learn how to do the same in yaml file format.



Leave a Comment

Your email address will not be published. Required fields are marked *

3 + four =