Example Java App Running in the Cloud via Kubernetes
Example Java App Running in the Cloud via Kubernetes
A developer talks about how he used Kubernetes, Istio, and Java to get a microservices application up and running.
Join the DZone community and get the full member experience.Join For Free
Over the last few weeks I've worked on a new sample application which demonstrates how to build microservices-based architectures. While there are still some minor things I'd like to add, I think the sample is pretty comprehensive now and a good option for developers, especially Java EE developers, to learn microservices and cloud-native patterns.
The example is available as open source. The GitHub repo is called cloud-native-starter.
Kubernetes, Istio, and Java
When building cloud-native applications, developers are challenged to figure out how to address topics like traffic routing, resiliency, distributed monitoring, service discoveries, and more. Fortunately most of these new challenges are handled by the orchestration platform Kubernetes and the service mesh Istio. This functionality works generically for microservices, regardless of the language they are implemented in and without changes to the application logic.
However, some functionality cannot be covered by orchestration platforms and service meshes. Instead it must be handled in the business logic of the microservices, for example application specific failover functionality, metrics, and fine-grained authorizations.
Java developers can leverage Eclipse MicroProfile to implement this functionality. MicroProfile is an extension to Java EE (Enterprise Edition) to build microservices-based architectures and it complements Kubernetes and Istio capabilities. In addition to the application specific logic which Kubernetes and Istio cannot handle, it also comes with convenience functionality that you typically need when developing microservices, for example mechanisms to invoke REST APIs and functionality to implement REST APIs including their documentation.
The example application follows these design principles:
- Leverage platforms as much as possible — do as little as possible in language-specific frameworks.
- Use open-source components for the core services of the application only.
- Make the first time experience as simple as possible.
- Be able to run the application in different environments.
Let me explain the design principles in more detail.
Leverage Platforms as Much as Possible — Do as Little as Possible in Language-Specific Frameworks
The advantage of using Kubernetes and Istio for features like traffic management is that these features are language agnostic. Cloud-native applications can be, and often are, polyglot. This allows developers to pick the best possible languages for the specific tasks.
Use Open-Source Components for the Core Services of the Application Only
In my role as a developer advocate I talk with many developers. Pretty much everyone loves open source. In order to reach as many developers as possible, the sample application only uses open source projects for the core services of the application. For example, the Java stack leverages OpenJ9, OpenJDK from AdoptOpenJDK, OpenLiberty, and MicroProfile. Kubernetes and Istio are obviously open source projects as well. The components of the application that are not available as open source are optional and can be exchanged.
Make the First Time Experience as Simple as Possible
There are many samples, snippets, articles, and tutorials available for the various cloud-native features and many of them are really good. However, I've had issues running some of these features together in one application. Sometimes they used different Java stacks, sometimes different versions, and sometimes the articles were outdated.
The example application shows several features working together (see below for details). There are also scripts to deploy services very easily, basically one script per service, similar to the 'cf push' experience for Cloud Foundry applications.
Be Able to Run the Application in Different Environments
Fortunately this is one of the main advantages of Kubernetes since you can run workloads in on-premises, hybrid, or public cloud infrastructures. The repo has instructions how to deploy the application to Minikube and to the managed IBM Cloud Kubernetes Service.
Functionality of the Sample Application
The project demonstrates the following functionality:
- Dockerizing Java MicroProfile services
- Traffic management
- Authentication and authorization
- REST APIs implementations including documentation
- REST API invocations
- Monitoring and metrics
- Distributed logging and monitoring
This diagram shows the services and components:
The web application invokes an API of a BFF (backend for front-end) service to display articles with authors.
Call to Action
If you want to learn cloud-native applications, get the code of the example application and follow the instructions to set up a local Minikube environment and to deploy the microservices. If you have already a Kubernetes cluster, the setup should not take longer than half an hour.
You can also run this application on the IBM Cloud Kubernetes Service, which is a managed service that comes with an Istio plugin. IBM provides an IBM Cloud Lite account, which is free, no credit card is required and there is no time restriction. Then follow these instructions to deploy the services to the IBM Cloud.
I also want to thank everyone who has helped to create this application, especially Harald Uebele who has written a lot of the code and scripts.
Published at DZone with permission of Niklas Heidloff , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.