Bring Java developers to Openshift using JKube

Objective: Microservices architecture has taken the software development world by storm. It is style of creating small, individual application posses a single responsibility who all communicated via a lightweight convention like REST over Http. In software programming java is the prominent technology that most of enterprises using since last 20 years and thus there is plethora of java developers exist and technology receives constant upgrade and innovations. One such industry adopted microservice development framework is spring boot and today major java based microservices are built using it.

To have the benefit of microservices, the de-facto deployment platform is cloud PaaS and, in that domain, kubernetes is the primary technology whose enterprise support product is Red Hat Openshift container platform. With Dev Ops culture and small teams’ adoption, the teams own from development to deployment — — — — — ‘if you built it, you run it’. This creates problem for development team, as now they need to invest resources to learn openshift and container technologies. Kubernetes has a steep learning curve, however, and it adds an additional layer of operations to the familiar Java development workflow.

This post will illustrate how using known / existing skillset we can bring java developer comfortably create application container image and deploy the same in openshift container platform.

Existing process for app deploys in openshift:

Classical way to deploy application in container platform requires below steps to follow.

  1. Developer to draft their docker file in which they need to mention the base image (java, nodejs, python etc) and then docker specific instructions.
  2. Use docker or any cri tool to create docker images.

3. Push the image to any accessible container image registry.

4. Draft deployment resource artifacts (yml files) and refer that image.

5. Use cluster client oc and deploy using those artifacts files.

Proposed Solution: To solve the above discussed issue of openshift / kubernetes deployment of java application we need to devise a process which speaks same language of developers and make the entire deployment lifecycle transparent to them. We need not provide any separate tool to learn for developers, instead need something which can work with existing skillset.

Eclipse JKube is the project which is not an effort from scratch. It was earlier called Fabric8 Maven Plugin. It is just refactored, and rebranded version of the project targeted towards Java developers who are working on top of Kubernetes. JKube is a maven plugin which focus on two tasks, building Docker image and generating kubernetes descriptors. To use the plugin, only addition the plugin xml fragment in existing pom file is what’s least is required.

Table 1: Default Eclipse JKube goals

Configuration : The plugin has three level of configurations.

· Zero-config: makes some very opinionated decisions based on data from existing pom file. This is very useful for quick start and it takes everything as default.

· XML plugin configuration: A subset of possible resource objects can be configured with a dedicated XML syntax. XML based configuration is only partially implemented and is not recommended for use right now.

· Kubernetes & OpenShift resource fragments: This plugin supports external Dockerfile as well. Resource descriptors can be provided as external YAML files which will build a base skeleton for the applicable resource.

Let’s See some code- demo:

· For this demo, we have used RHEL host vm .Docker daemon is required as internally its being used to create docker image.

Java & maven needs to be installed .

· We have kubernetes and openshift plugins in Jkube. In our demo we will use Openshift one. We do need to have one cluster and logged in to a namespace. In our case we created a project ‘jkube-demo’.

Need to show how an existing app can be used without changing and special code/config but only plugin declaration in pom file . We have used one sample application from git and cloned it to a particular location. Delete any existing Dockerfile , target or other folders. Only src folder and pom file to stay. ls & Tree command will give project structure .

spring boot project structure

Open pom.xml file in any text editor and add below plugin in plugins section.

And based on installed java version, update the property of jdk version. We have used v1.11

The setup make some opinionated decisions e.g. base image jkube/jkube-java-binary-s2i is chosen which enables Jolokia and jmx_exporter. It also comes with a sophisticated startup script. As we all know about mvn goals and we can invoke them individually or in sequence. To execute complete phase i.e. compile and install package jar create image in single command we use

$mvn package oc:build

This will create the Docker image against a running Docker daemon. When connected to an OpenShift cluster then a S2I build will be performed on OpenShift which at the end creates an ImageStream.

· To generate openshift deployment artifacts we use $mvn oc:resource

Which will showcase below output in console and generate openshift deployment artifacts inside target/classes/META-INF folder.

generated artifacts

· To deploy in logged in cluster use => $mvn oc:deploy

Which creates openshift deploymentconfig , services spin up pods and corresponding route as well to access the application from outside of the cluster, as the plugin by default creates service of CLusterIp type.

Check the pods status and when its up & running access the application using route.

· There is another goal that this plugin provides and that is to remove your application from cluster . You may try this using

$mvn oc:undeploy

Which eventually deletes all objects that has been created using earlier commands.

Summary : This concludes this post, where we learnt how a java developer using his existing maven skill can build container image create deployment artifacts, deploy / undeploy in existing open shift cluster. We have seen that we haven’t used any other third-party tool. This helps and inspires more java developer who are new to kubernetes/openshift world to deploy their application easily in container form. Developers they can focus their time in business logic implementations and for deployment & testing Jkube will do the necessary.

--

--

--

Cloud Developer Advocate. Post Graduate in Computer Applications with 11+ years of experience in Software Development & cloud onboarding.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

UX: Flash interactions

Top 4 CI/CD Misinterpretations CIOs Should Avoid

Test Automation: What is it good for… | spriteCloud

How To Apply a Sync Slicer in Power Bi Desktop

10 Movies To Get You Coding Again

Test Automation in CI/CD: Part 2

How to configure virtual host for laravel

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
abhiroop ghatak

abhiroop ghatak

Cloud Developer Advocate. Post Graduate in Computer Applications with 11+ years of experience in Software Development & cloud onboarding.

More from Medium

Deploy Percona for MongoDB with SSL/TLS

How to Fix NET::ERR_CERT_SYMANTEC_LEGACY Error?

Local Storage vs Cookies: Where to securely store data on the client-side?

Explaining Types of Application Software with Examples