Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

Openshift: Lab 13 – How to deploy a Java application on Kubernetes

Prerequisites

What you will learn

In this learning path, you will:

  • Deploy a MySQL database with configured environment variables
  • Deploy the Spring Pet Clinic application from source code with configured environment variables

How long will this learning path take?

  • About 30-45 minutes

In this lesson, you will:

  • Create a deployment of an ephemeral instance of MySQL
  • Set the environment variables for credentials and database name


Creating the deployment

The Pet Clinic application uses a MySQL database to store data, and this lesson creates that MySQL installation and the necessary database (petclinic) in the same OpenShift project as the Pet Clinic app.

Info alert:While this lesson is specific to the Pet Clinic application, the same steps are used for any application for which you wish to use a MySQL database in OpenShift.

  1. Begin by logging into the Developer Sandbox. The dashboard will appear in your browser.
  2. Select the Developer perspective (Figure 1, Callout 1), then click the +Add option (Figure 1, Callout 2), then click the Database panel (Figure 1, Callout 3).Figure 1: Prepare to install the database using the web-based dashboard.
  3. The Databases section of the Developer Catalog is displayed. Click on the MySQL (Ephemeral) panel (Figure 2).Figure 2: Selecting the MySQL Ephemeral database.
  4. The description of the MySQL Ephemeral database is displayed. Click the Instantiate Template button to continue (Figure 3).Figure 3: Brief description of MySQL Ephemeral database instance.
  5. The Instantiate Template panel is displayed. There are several options. 
  6. Supply the following four values (Figure 4):
    • MySQL Connection Username: petclinic
    • MySQL Connection Password: petclinic
    • MySQL root user Password: petclinic
    • MySQL Database Name: petclinic
       
    • Figure 4: Preparing to create the MySQL instance.
  7. Click Create and the installation will happen. You will see the icon in your dashboard (Figure 5).Figure 5: MySQL is up and running.

That’s it. The ephemeral instance of MySQL is up and running as an OpenShift service (named mysql). In the next lesson, you will create the Spring Pet Clinic application that uses this database.

Deploy the Spring Pet Clinic application with configured environment variables

Camels, pythons, and cats — oh my! In this scenario, the line of animals and their owners has surrounded the building, and the employees at the Pet Clinic can’t keep up with demand. The clinic needs an application to help them run the clinic more efficiently. Management wants to keep track of the pets, their owners, and the veterinarians that work at the Pet Clinic. You’ll need to create a set of microservices that lets employees view the list of veterinarians and their specialties, add new pets and owners, plus update information about existing pets and owners, and manage their visits. Of course, the application needs to be delivered yesterday.

In order to get full benefit from taking this lesson, you need to:

  • Have access to the OpenShift dashboard
  • Have the MySQL database service available

In this lesson, you will:

  • Create a deployment of the Spring Pet Clinic application with the necessary environment variables

Deploy from source using S2I

One of the ways to create an application is by using the Source-To-Image (S2I) feature. The S2I feature allows you to import source code from a git repository and let OpenShift automatically build and start an image. In this lesson, you will create the Spring Pet Clinic app from source.

Begin by logging into your sandbox; the dashboard will appear in your browser.

Select the Developer perspective (Figure 1, Callout 1), then click the +Add option (Figure 1, Callout 2), then click the Git Repository panel (Figure 1, Callout 3).

Select the Developer perspective then click the +Add option then click the Git Repository panel
Figure 1: Prepare to create the app using source code.

When the Import from Git panel is displayed, enter the following value for the git repo (Figure 2, Callout 1): https://github.com/redhat-developer-demos/spring-petclinic

You will see the Import is not possible error message. When you specify a Git repo, OpenShift will inspect it and try to determine the best way to build the source code.

The three options are:

  • Build from source as-is using a build image for the programming language, e.g. Java
  • Use any Dockerfile in the source code to build the app
  • Use any development configuration file (devfile) to build the app

In this case, the source code contains a development configuration file (devfile) that is outdated, causing the error. You need to override this by clicking on the Edit Import Strategy link (Figure 2, Callout 2).

Override the import error by clicking on the Edit Import Strategy link.
Figure 2: Specify the Git repo to Import.

After selecting the Edit Import Strategy link, choose the Builder Image option (Figure 3).

Choose the Builder Image option
Figure 3: Choosing the Java builder image.

Scroll down and open the Resource type dropdown list. Select the Deployment option (Figure 4).

Scroll down and open the Resource type dropdown list then select the Deployment option
Figure 4: Resource types for an application.

Select the link to access the advanced options for the Build configuration (Figure 5).

Select the link to access the advanced options for the Build configuration
Figure 5: Preparing to add environment variables to the Build configuration.

Enter the two necessary Environment variables:

  • SPRING_PROFILES_ACTIVE mysql
  • MYSQL_URL jdbc:mysql://mysql:3306/petclinic

Click Create to build the application (Figure 6).

Enter the two necessary Environment variables and click Create to build the application
Figure 6: Adding environment variables prior to the build.

The build will begin. After a few minutes, you will see the app icon showing the completed build. You will know the build is complete when the outer ring turns dark blue. When it’s complete, click the Open URL link to display the app (Figure 7).

Click the Open URL link to display the app
Figure 7: View the app in your browser.

Your browser will open to the Spring Petclinic app (Figure 8).

Your browser will open to the Spring Petclinic app
Figure 8: The app is up and running.

Summary

Congratulations. You’ve done it. We have walked you through a simplistic example that demonstrates the power of OpenShift S2I.  This lesson has walked you through entering required parameters and creating the Spring Petclinic app from source code.. 

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at <a href="https://www.cotocus.com/">Cotocus</a>. I share tech blog at <a href="https://www.devopsschool.com/">DevOps School</a>, travel stories at <a href="https://www.holidaylandmark.com/">Holiday Landmark</a>, stock market tips at <a href="https://www.stocksmantra.in/">Stocks Mantra</a>, health and fitness guidance at <a href="https://www.mymedicplus.com/">My Medic Plus</a>, product reviews at <a href="https://www.truereviewnow.com/">TrueReviewNow</a> , and SEO strategies at <a href="https://www.wizbrand.com/">Wizbrand.</a> Do you want to learn <a href="https://www.quantumuting.com/">Quantum Computing</a>? <strong>Please find my social handles as below;</strong> <a href="https://www.rajeshkumar.xyz/">Rajesh Kumar Personal Website</a> <a href="https://www.youtube.com/TheDevOpsSchool">Rajesh Kumar at YOUTUBE</a> <a href="https://www.instagram.com/rajeshkumarin">Rajesh Kumar at INSTAGRAM</a> <a href="https://x.com/RajeshKumarIn">Rajesh Kumar at X</a> <a href="https://www.facebook.com/RajeshKumarLog">Rajesh Kumar at FACEBOOK</a> <a href="https://www.linkedin.com/in/rajeshkumarin/">Rajesh Kumar at LINKEDIN</a> <a href="https://www.wizbrand.com/rajeshkumar">Rajesh Kumar at WIZBRAND</a> <a href="https://www.rajeshkumar.xyz/dailylogs">Rajesh Kumar DailyLogs</a>

Related Posts

List of all Job Roles, Job Titles in Software and IT Companies

The software and IT industry is home to a diverse array of job roles and titles, reflecting the dynamic and ever-evolving nature of technology. From core technical…

Read More

Best DevOps Tools in 2024

here’s a clear, structured breakdown of the Best DevOps Tools (grouped by categories), so you can use it for learning, training, or posts. 🚀 Best DevOps Tools…

Read More

OpenShift Install & Configurations using OpenShift Local in windows laptops/desktops

Below is the 100% correct and updated step-by-step guide to install and configure OpenShift Local (aka CRC) on Windows 10/11 laptops or desktops using the correct crc…

Read More

Openshift: How to configure Azure openshift ARO with Custom Domain

Step-by-Step Guide: Configuring Azure Red Hat OpenShift (ARO) with a Custom Domain Setting up a custom domain for your ARO cluster involves both Azure and DNS provider…

Read More

Openshift: Lab 10 – View performance information using the OpenShift web console

Rajesh Kumar I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at Cotocus. I share tech blog at DevOps School, travel stories at…

Read More

Openshift: How to add Helm Repository in Openshift

Adding a Helm repository in OpenShift is a common step to manage and deploy Helm charts in your OpenShift cluster. OpenShift supports Helm CLI out of the…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x