How to deploy a Java application on Kubernetes in minutes

Move your legacy Java application into a container and deploy it to Kubernetes. The Developer Sandbox for Red Hat OpenShift (Developer Sandbox) is a free OpenShift cluster that gives you access to the cutting-edge technologies built on Kubernetes. A quick sign-up gets you a cluster and access to a set of developer tools and services. 

In this learning path created by Don Schenck, you will learn how to create a set of microservices and move this Spring Pet Clinic example application into a container using the Source-to-Image (s2i) feature.

A MySQL database is needed for the application, and because this is a lesson (versus production), the ephemeral version of MySQL will be used.

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

  • Have access to the OpenShift dashboard

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).

    Select the Developer perspective then click the +Add option then click the Database panel
    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).

    When you see the Databases section of the Developer Catalog, click on the MySQL (Ephemeral) panel
    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).

    When you see the description of the MySQL Ephemeral database, click the Instantiate Template button to continue
    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
    • Click Create to create the MySQL instance
      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).

    Click Create. When the installation happens, the icon will appear in your dashboard
    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.

Previous resource
Overview: How to deploy a Java application on Kubernetes in minutes
Next resource
Deploy the Spring Pet Clinic application with configured environment variables