Springboot + Redhat Openshift

Deploying your first Springboot application on Openshift

In this blog, you will be learning to deploy a spring boot app without installing Openshift on your system.

Pratik Singhal
Fnplus Club

--

The purpose of writing this article is to save hours of your time searching for the right way to deploy your spring-boot application on the Redhat Openshift Platform.
Since I have wasted a lot of time trying to understand, I won’t waste yours… I promise and hence I decided on documenting everything for you at a place.

Pre-requisites:
1. Git installed on your local system.
2. Basic understanding of using a command-line on your preferred choice of the operating system.

Assuming the prerequisites are satisfied, let’s get started!

Step- 1: Create an account on the Openshift platform by visiting here. Click on “Log In” at the top right corner of the screen. Openshift Online page gets loaded. Now click on “Log In With Red Hat”.

Click on the grey button.

Step- 2: On the page, that opens up, click on the Github symbol from the list of OAuth providers and sign in with your Github account.

Click on Github icon (first icon in the row of icons)

Step- 3: After finishing the authentication, you can see a screen that shows “Active Subscriptions”. Click on the Open Web Console button.

Click on Open Web Console (the blue button)

Step- 4: On doing so, it’ll take us to the Redhat Openshift Online Console or we can call it Openshift web console. Make sure it says, Administrator on the top left corner of your console, as shown in the image.

If it doesn’t show any projects for you, don’t panic we are going to make one in the very next step.

The red circled part should show the Administrator. If it doesn’t, just click on it and select the Administrator.

Step- 5: Making the project: Click on Create Project button and give it a name, display name and description as you please. It won’t make much difference right now. So the name of the project for me is trial”.

Now, we need to take a little detour from Openshift and make our git repository ready for the Openshift project.

  • Create a spring-boot project according to your need using spring initializr.
  • Unzip it in your local system. Open up a terminal/ command line in that folder. For example, I created a project named spring-boot-trial and unzipped it in a folder called “workspace”.
This is how the unzipped project looks like. Click on the address bar above and type cmd.

So, assuming that Git in your system is ready and set up let’s continue.

  • Go to your Github account and create a new repository. Name it as you please.
Create a new repository in your Github account and name it as you please and click on Create Repository.
  • Click on the button circled red in the image below and head back to the file explorer where the command line/terminal is opened.
Click on the red circled button
  • In the terminal, type the following commands exactly as shown
$ git init$ git add .$ git commit -m "any commit message here"
Execute the commands in the root of your project folder.
  • After executing these commands, right-click on the terminal and select paste.
Press enter and wait for a few seconds. Your repository on Github is ready. Just visit the repository page and refresh it.
  • Click on Clone or Download and copy the link by clicking on the small clipboard button as shown in the image below.
  • So, we are now back on the track. Open the Openshift Web Console and click on the project that you created in Step-5.
    If you are seeing the screen as below, just log in using the credentials username — account email and password — account password.
Login using developer/developer as credentials.
  • Step- 6: After clicking on the project, a screen similar to the image below should appear. Just click on the Administrator in the top left corner and select Developer from the drop-down menu.
Click on the top left and select Developer.
  • Step- 7: On the screen that loads, click on From Git.
Click on From Git tile.
  • In the Git Repo URL section, paste the link we copied from the Github repository.
    Note: Click on More Advanced Options to specify the branch name(if-any). By default, the branch is master and we do not need to specify it.

Context Dir is used in case your project is inside another folder. If that’s the case just replace the forward slash with the name of your folder which contains your project.

  • Step- 8: Scroll down to select Builder Image. It is supposed to be Java in our case. After clicking on Java, make sure to change the Java version to 8 from the drop-down that appears.
Click on Java and the select version as 8.
  • Step- 9: Let other options be as they are, no fiddling with them. Just make sure that the checkbox in the Advanced Options section is checked as shown in the image below and then click on Create.
The last checkbox must be checked.
  • Step- 10: Click on the penguin logo on the screen. We can see that a build is already in progress. Keep a little patience and wait for the build to finish.
The build is running. Wait for Build #1 to finish.
  • As soon as the build is finished, a pod will automatically be deployed. Congratulations, you have successfully deployed your spring-boot application on Redhat Openshift nonchalantly.
Our pod is up and running successfully.
  • Now, you might be wondering, how to access this just deployed pod.
    Well, that’s right in front of you under the Routes section.
    The link in this section is your newly deployed spring-boot application(no more localhost:8080).
  • Since I had “/” configured in my spring-boot application, hence it shows the output “Hello World” on visiting the link.

Hope this article helps. Feel free to comment for doubts.
I have wasted hours, you shouldn’t. Let me know if this saves your time.
And hey! Do you know you can clap for an article 50 times? Damn, that’s awesome!

--

--

Pratik Singhal
Fnplus Club

Fluttering all the way in to tech world | Flutter Enthusiast | Final Year Engineering Student at S.R.M. I.S.T. | Always Available |