{"id":50022,"date":"2025-07-10T07:58:52","date_gmt":"2025-07-10T07:58:52","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=50022"},"modified":"2026-02-21T07:33:35","modified_gmt":"2026-02-21T07:33:35","slug":"openshift-how-to-deploy-a-java-application-on-kubernetes","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/openshift-how-to-deploy-a-java-application-on-kubernetes\/","title":{"rendered":"Openshift: Lab 13 &#8211; How to deploy a Java application on Kubernetes"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">Prerequisites<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Access to the OpenShift dashboard<\/li>\n\n\n\n<li>Access to the\u00a0<a href=\"https:\/\/developers.redhat.com\/content-gateway\/link\/3881643\" target=\"_blank\" rel=\"noreferrer noopener\">Developer Sandbox<\/a><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">What you will learn<\/h3>\n\n\n\n<p>In this learning path, you will:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Deploy a MySQL database with configured environment variables<\/li>\n\n\n\n<li>Deploy the Spring Pet Clinic application from source code with configured environment variables<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">How long will this learning path\u00a0take?<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>About 30-45 minutes<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">In this lesson, you will:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create a deployment of an ephemeral instance of MySQL<\/li>\n\n\n\n<li>Set the environment variables for credentials and database name<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\">\n\n\n\n<h2 class=\"wp-block-heading\">Creating the deployment<\/h2>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Begin by logging into the Developer Sandbox. The dashboard will appear in your browser.<\/li>\n\n\n\n<li>Select the\u00a0<strong>Developer<\/strong>\u00a0perspective (Figure 1, Callout 1), then click the\u00a0<strong>+Add\u00a0<\/strong>option (Figure 1, Callout 2), then click the\u00a0<strong>Database<\/strong>\u00a0panel (Figure 1, Callout 3).<a href=\"https:\/\/developers.redhat.com\/sites\/default\/files\/deploy_java_app_lp_fig_1.png\" target=\"_blank\" rel=\"noopener\"><\/a>Figure 1: Prepare to install the database using the web-based dashboard.<\/li>\n\n\n\n<li>The Databases section of the Developer Catalog is displayed. Click on the\u00a0<strong>MySQL (Ephemeral)<\/strong>\u00a0panel (Figure 2).<a href=\"https:\/\/developers.redhat.com\/sites\/default\/files\/deploy_java_app_lp_fig_2.png\" target=\"_blank\" rel=\"noopener\"><\/a>Figure 2: Selecting the MySQL Ephemeral database.<\/li>\n\n\n\n<li>The description of the MySQL Ephemeral database is displayed. Click the\u00a0<strong>Instantiate Template<\/strong>\u00a0button to continue (Figure 3).<a href=\"https:\/\/developers.redhat.com\/sites\/default\/files\/deploy_java_app_lp_fig_3.png\" target=\"_blank\" rel=\"noopener\"><\/a>Figure 3: Brief description of MySQL Ephemeral database instance.<\/li>\n\n\n\n<li>The Instantiate Template panel is displayed. There are several options.\u00a0<\/li>\n\n\n\n<li>Supply the following four values (Figure 4):\n<ul class=\"wp-block-list\">\n<li><strong>MySQL Connection Username:<\/strong>\u00a0petclinic<\/li>\n\n\n\n<li><strong>MySQL Connection Password<\/strong>: petclinic<\/li>\n\n\n\n<li><strong>MySQL root user Password<\/strong>: petclinic<\/li>\n\n\n\n<li><strong>MySQL Database Name<\/strong>: petclinic<br>\u00a0<\/li>\n\n\n\n<li><a href=\"https:\/\/developers.redhat.com\/sites\/default\/files\/deploy_java_app_lp_fig_4.png\" target=\"_blank\" rel=\"noopener\"><\/a>Figure 4: Preparing to create the MySQL instance.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Click\u00a0<strong>Create<\/strong>\u00a0and the installation will happen. You will see the icon in your dashboard (Figure 5).<a href=\"https:\/\/developers.redhat.com\/sites\/default\/files\/deploy_java_app_lp_fig_5.png\" target=\"_blank\" rel=\"noopener\"><\/a>Figure 5: MySQL is up and running.<\/li>\n<\/ol>\n\n\n\n<p>That&#8217;s it. The ephemeral instance of MySQL is up and running as an OpenShift service (named\u00a0<strong>mysql<\/strong>).\u00a0In the next lesson, you will create the Spring Pet Clinic application that uses this database.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"732\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2025\/07\/image-10.png\" alt=\"\" class=\"wp-image-50024\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2025\/07\/image-10.png 600w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2025\/07\/image-10-246x300.png 246w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"732\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2025\/07\/image-11.png\" alt=\"\" class=\"wp-image-50025\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2025\/07\/image-11.png 600w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2025\/07\/image-11-246x300.png 246w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"491\" height=\"487\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2025\/07\/image-12.png\" alt=\"\" class=\"wp-image-50026\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2025\/07\/image-12.png 491w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2025\/07\/image-12-300x298.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2025\/07\/image-12-150x150.png 150w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2025\/07\/image-12-80x80.png 80w\" sizes=\"auto, (max-width: 491px) 100vw, 491px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"422\" height=\"1024\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2025\/07\/image-13-422x1024.png\" alt=\"\" class=\"wp-image-50027\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2025\/07\/image-13-422x1024.png 422w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2025\/07\/image-13-124x300.png 124w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2025\/07\/image-13.png 425w\" sizes=\"auto, (max-width: 422px) 100vw, 422px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"381\" height=\"302\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2025\/07\/image-14.png\" alt=\"\" class=\"wp-image-50028\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2025\/07\/image-14.png 381w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2025\/07\/image-14-300x238.png 300w\" sizes=\"auto, (max-width: 381px) 100vw, 381px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Deploy the Spring Pet Clinic application with configured environment variables<\/h2>\n\n\n\n<p>Camels, pythons, and cats \u2014 oh my!\u00a0In this scenario, the line of animals and their owners has surrounded the building, and the employees at the Pet Clinic can\u2019t 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\u2019ll 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.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">In order to get full benefit from taking this lesson, you need to:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Have access to the OpenShift dashboard<\/li>\n\n\n\n<li>Have the MySQL database service available<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">In this lesson, you will:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create a deployment of the Spring Pet Clinic application with the necessary environment variables<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\">\n\n\n\n<h3 class=\"wp-block-heading\">Deploy from source using S2I<\/h3>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>Begin by logging into your sandbox; the dashboard will appear in your browser.<\/p>\n\n\n\n<p>Select the\u00a0<strong>Developer<\/strong>\u00a0perspective (Figure 1, Callout 1), then click the\u00a0<strong>+Add<\/strong>\u00a0option (Figure 1, Callout 2), then click the\u00a0<strong>Git Repository<\/strong>\u00a0panel (Figure 1, Callout 3).<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/developers.redhat.com\/sites\/default\/files\/deploy_java_app_lp_fig_2.1.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/developers.redhat.com\/sites\/default\/files\/styles\/article_floated\/public\/deploy_java_app_lp_fig_2.1.png?itok=CTbQvvsp\" alt=\"Select the Developer perspective then click the +Add option then click the Git Repository panel\"><\/a><figcaption class=\"wp-element-caption\">Figure 1: Prepare to create the app using source code.<\/figcaption><\/figure>\n\n\n\n<p>When the Import from Git panel is displayed, enter the following value for the git repo (Figure 2, Callout 1):\u00a0<a href=\"https:\/\/github.com\/redhat-developer-demos\/spring-petclinic\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/redhat-developer-demos\/spring-petclinic<\/a><\/p>\n\n\n\n<p>You will see the\u00a0<strong>Import is not possible<\/strong>\u00a0error message. When you specify a Git repo, OpenShift will inspect it and try to determine the best way to build the source code.<\/p>\n\n\n\n<p>The three options are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Build from source as-is using a build image for the programming language, e.g. Java<\/li>\n\n\n\n<li>Use any Dockerfile in the source code to build the app<\/li>\n\n\n\n<li>Use any development configuration file (<code>devfile<\/code>) to build the app<\/li>\n<\/ul>\n\n\n\n<p>In this case, the source code contains a development configuration file (<code>devfile<\/code>) that is outdated, causing the error. You need to override this by clicking on the\u00a0<strong>Edit Import Strategy<\/strong>\u00a0link (Figure 2, Callout 2).<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/developers.redhat.com\/sites\/default\/files\/deploy_java_app_lp_fig_2.2.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/developers.redhat.com\/sites\/default\/files\/styles\/article_floated\/public\/deploy_java_app_lp_fig_2.2.png?itok=FGcz0LnE\" alt=\"Override the import error by clicking on the Edit Import Strategy link.\"><\/a><figcaption class=\"wp-element-caption\">Figure 2: Specify the Git repo to Import.<\/figcaption><\/figure>\n\n\n\n<p>After selecting the\u00a0<strong>Edit Import Strategy<\/strong>\u00a0link, choose the\u00a0<strong>Builder Image<\/strong>\u00a0option (Figure 3).<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/developers.redhat.com\/sites\/default\/files\/deploy_java_app_lp_fig_2.3.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/developers.redhat.com\/sites\/default\/files\/styles\/article_floated\/public\/deploy_java_app_lp_fig_2.3.png?itok=ihnZN4ck\" alt=\"Choose the Builder Image option\"><\/a><figcaption class=\"wp-element-caption\">Figure 3: Choosing the Java builder image.<\/figcaption><\/figure>\n\n\n\n<p>Scroll down and open the\u00a0<strong>Resource type<\/strong>\u00a0dropdown list. Select the\u00a0<strong>Deployment<\/strong>\u00a0option (Figure 4).<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/developers.redhat.com\/sites\/default\/files\/deploy_java_app_lp_fig_2.4.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/developers.redhat.com\/sites\/default\/files\/styles\/article_floated\/public\/deploy_java_app_lp_fig_2.4.png?itok=Hsi2fzWB\" alt=\"Scroll down and open the Resource type dropdown list then select the Deployment option\"><\/a><figcaption class=\"wp-element-caption\">Figure 4: Resource types for an application.<\/figcaption><\/figure>\n\n\n\n<p>Select the link to access the advanced options for the Build configuration (Figure 5).<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/developers.redhat.com\/sites\/default\/files\/deploy_java_app_lp_fig_2.5.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/developers.redhat.com\/sites\/default\/files\/styles\/article_floated\/public\/deploy_java_app_lp_fig_2.5.png?itok=BzeLlpu0\" alt=\"Select the link to access the advanced options for the Build configuration\"><\/a><figcaption class=\"wp-element-caption\">Figure 5: Preparing to add environment variables to the Build configuration.<\/figcaption><\/figure>\n\n\n\n<p>Enter the two necessary Environment variables:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>SPRING_PROFILES_ACTIVE\u00a0mysql<\/li>\n\n\n\n<li>MYSQL_URL\u00a0jdbc:mysql:\/\/mysql:3306\/petclinic<\/li>\n<\/ul>\n\n\n\n<p>Click\u00a0<strong>Create<\/strong>\u00a0to build the application (Figure 6).<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/developers.redhat.com\/sites\/default\/files\/deploy_java_app_lp_fig_2.6.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/developers.redhat.com\/sites\/default\/files\/styles\/article_floated\/public\/deploy_java_app_lp_fig_2.6.png?itok=l4FKeSwN\" alt=\"Enter the two necessary Environment variables and click Create to build the application\"><\/a><figcaption class=\"wp-element-caption\">Figure 6: Adding environment variables prior to the build.<\/figcaption><\/figure>\n\n\n\n<p>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&#8217;s complete, click the\u00a0<strong>Open URL<\/strong>\u00a0link to display the app (Figure 7).<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/developers.redhat.com\/sites\/default\/files\/deploy_java_app_lp_fig_2.7.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/developers.redhat.com\/sites\/default\/files\/styles\/article_floated\/public\/deploy_java_app_lp_fig_2.7.png?itok=LwLx9pAf\" alt=\"Click the Open URL link to display the app\"><\/a><figcaption class=\"wp-element-caption\">Figure 7: View the app in your browser.<\/figcaption><\/figure>\n\n\n\n<p>Your browser will open to the Spring Petclinic app (Figure 8).<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/developers.redhat.com\/sites\/default\/files\/deploy_java_app_lp_fig_2.8.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/developers.redhat.com\/sites\/default\/files\/styles\/article_floated\/public\/deploy_java_app_lp_fig_2.8.png?itok=yjva86Qd\" alt=\"Your browser will open to the Spring Petclinic app\"><\/a><figcaption class=\"wp-element-caption\">Figure 8: The app is up and running.<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Summary<\/h3>\n\n\n\n<p>Congratulations. You&#8217;ve done it. We have walked you through a simplistic example that demonstrates the power of OpenShift S2I. \u00a0This lesson has walked you through entering required parameters and creating the Spring Petclinic app from source code..\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Prerequisites What you will learn In this learning path, you will: How long will this learning path\u00a0take? In this lesson, you will: Creating the deployment The Pet Clinic application uses&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[5153],"tags":[],"class_list":["post-50022","post","type-post","status-publish","format-standard","hentry","category-openshift"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/50022","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=50022"}],"version-history":[{"count":6,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/50022\/revisions"}],"predecessor-version":[{"id":59083,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/50022\/revisions\/59083"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=50022"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=50022"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=50022"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}