By clicking “Accept All Cookies”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. View our Privacy Policy for more information.
Resources
>
Blog
>
Article
The Docker, Kubernetes, and Openshift logos side-by-side.
January 23, 2018

OpenShift Deployments

In this tutorial, I’ll deploy a containerized java application with its mysql database. In this setup, you’ll be able to build and quickly redeploy the java app.

In this tutorial, I’ll deploy a containerized java application with its mysql database. In this setup, you’ll be able to build and quickly redeploy the java app. This is what I use locally when working on applications that will run in OpenShift. This involves a complete setup and teardown of an application in OpenShift.

If an application is going to run in OpenShift, it’s important for developers to be able to run it locally with settings as similar to production as possible. The best way to accomplish OpenShift deployments is to run your app inside an actual OpenShift cluster.

Minishift

Minishift is a single node (vm) Kubernetes cluster with some wrapper functionality to make certain tasks easier. This provides all the functionality one would need to develop on the OpenShift platform. This excludes OpenShift deployments of clusters — I wouldn’t recommend installing Minishift anywhere except on your dev box.

The built-in features on top of the normal installation:

  • Default users and a projecteval $(minishift oc-env)
  • Running the above command will set up the oc-cli to point your OpenShift cluster. Since it is a real OpenShift cluster, you can use the same commands that you’d use in production.
  • Running the above commands will set up your docker environment to use the docker client/socket on the Minishift virtual machine. Benefits include using the already allotted resources for Minishift and using the same docker version as the OpenShift version that you’re using (should match production).

Installing and Running Minishift

Install Minishift according to your OS requirements. I recommend using Homebrew for Mac and probably downloading the tar for Windows and Linux. Run this command to start it up:

If running Jenkins and Nexus as well as your app, feel free to bump up the memory. I usually run it with 6GB, and depending on my image sizes, 30GB or 50GB. With `minishift delete` everything is cleared out including the specified disk space, so feel free to go nuts.

OpenShift Builds and OpenShift Deployments

Setting up local build and deployments for spring-petclinic

This application is just a spring application that compiles into a war and requires a connection to a mysql database to work. I made some alterations to the application to work this way. That way, if the site comes up it means it successfully connected the mysql db.

  1. Fork spring-petclinic-framework so that you can make changes and check in your changes
  2. Alter the Dockerfile
  • Set database defaults in Dockerfile
  • All those vales are specific to petclinic. Other apps will have different environment variables to set values such as these
  • All database configurations are consumed via environment variable, so they can be set in the docker file, or in any environment that they run.
  • As you can see in the last line of the docker file, I set the JDBC URL to be something it would never be. I expect to override this in every-runtime.
  • The same should probably be said for the password. It’s fine to keep it simple, and it can be used easily have the app run via docker-compose.
  • There’s a docker-compose file in the repo showing how to accomplish this.
  • For non-secret configurations, ideally set those as early as possible. So just set them in the dockerfile.

3.     Run update.sh

  • Essentially this will build your app into a container and deploy it to OCR, making it available for use immediately by OpenShift without requiring anything outside of your dev box.
  • This will run the oc-env and docker-env evaluate scripts so that the rest of the script can use the oc cli, as well as use the docker damon on the OpenShift vm.
  • Login to local OCR with docker so images can be pushed to it
  • Run mvn install to build a war
  • Run docker build to build the container specified in the dockerfile
  • Run docker push to push the container to OCR

4.     Edit and Run createApps.sh

  • Line 6 specifies the name of the app.
  • Edit app name in the scripts
  • Call the app whatever you want, or just keep it as is
  • Set configurations in config-map
  • The current setup will create a random password and set it for petclinic and the mysql db.

5.     Continue work on your project, and run update.sh at any point to build and redeploy your application.

6.     Once you want to tear everything down that this script has created, run deleteApps.sh

OpenShift Deployments – Final Thoughts

That’s all there is to it. With just a few shell commands, you’re deploying a multi-component application to OpenShift within minutes. If you have any thoughts or questions about OpenShift deployments, please reach out.


Ready to get started?

Contact Us

We'd love to learn more about your project and determine how we can help out.