XenonStack - A Stack Innovator

Deploying Microservices Based Java Application on Docker & Kubernetes

by Navdeep | November 17, 2017 |  Categories -  Docker, Kubernetes, Java, Microservices

Blog Image

 

Overview

 

Running Containers at any real-world scale requires container orchestration and scheduling platform like Docker Swarm, Apache Mesos, AWS ECS but the most popular out of it is Kubernetes. Kubernetes is an open source system for automating deployment and management of containerized applications. 

 

In this post, We’ll share the process how you can Develop and Deploy Microservices based Java Application on the Container Environment -  Docker and Kubernetes and adopt DevOps in existing Java Application.

 


 

Prerequisites

 

To follow this guide you need -

 

 

Kubernetes is an open source platform that automates container operations and Minikube is best for testing kubernetes.

 

You May also Love to Read Kubernetes Overview, Monitoring & Security

 

Kubectl is command line interface to manage kubernetes cluster either remotely or locally. To configure kubectl on your machine follow this link.

 

Shared Persistent Storage is permanent storage that we can attach to the kubernetes container so that we don`t lose our data even container died.we will be using GlusterFS as the persistent data store for kubernetes container applications.

 

Application Source Code is source code that we want to run inside a kubernetes container.

 

Dockerfile contains a bunch of commands to build java application.

 

The Registry is an online image store for container images.

 

The below-mentioned options are few most popular registries.

 

 


 

Creating a Dockerfile

 

The below-mentioned code is sample dockerfile for Java applications. In which we are using Maven 3 as the builder and OpenJDK 8 as Java development environment with Alpine Linux due to its very compact size.

 

 


 

Building Java Application Image

 

 

The below-mentioned command will build your application container image.

 


 

Publishing Container Image

 

Now we publish our Java application container images to any container registry like Docker Hub, AWS ECR, Google Container Registry, Private Docker Registry.

 

I am using docker hub registry to publish images to the Kubernetes cluster.

 

Create a account on docker hub and create a Public/Private Repository of your application name.

 

To login to your docker hub account. Execute the below-mentioned command.

 

 

Now we need to retag java application image and push them to docker hub container registry.

 

To Retag application container image

 

 

To Push application container Images

 

 

Similarly, we can push images to any of above-mentioned container registry like Docker Hub, AWS ECR, Google Container Registry, Private Docker Registry etc.

 


 

Setting Persistent Volume

 

Persistent Volume is only required if your application has to save some data other than a database like documents, images, video etc then we need to use the persistent volume that kubernetes support like was AWS EBC, CephFS, GlusterFS, Azure Disk, NFS etc.

 

I will be attaching GlusterFS volume as a persistent volume to the kubernetes container.

 

GlusterFS volumes are very simple and easy to create. Follow the below mentioned commands.

 

 

Setting Persistent Volume For Kubernetes

 


 

Creating Deployment files for Kubernetes

 

Deploying application on kubernetes with ease using deployment and service files either in JSON or YAML format.

 

  • Deployment File

Following Content is for “<name of application>.deployment.yml” file of python container application.

 

 

  • Service File

Following Content is for “<name of application>.service.yml” file of python container application.

 

 


 

Running Java Application on Kubernetes

 

Java Container Application can be deployed either by kubernetes Dashboard or Kubectl (Command line).

 

I`m explaining command line that you can use in production kubernetes cluster.

 

 

Now we have successfully deployed Java Application on Kubernetes.

 


 

Verification

 

We can verify application deployment either by using Kubectl or Kubernetes Dashboard.

 

Below mentioned command will show you running pods of your application with status running/terminated/stop/created.

 

 

Result of above command

 

Information of Kubernetes Pods

 


 

Testing

 

Get the External Node Port using the below-mentioned command.External Node Port is in the range from 30000 to 65000.

 

Launch web Browser and open any of the below-mentioned URLs.

 

 

  • http://<kubernetes master ip address >: <application service port number>

  • http://<cluster ip address >: <application port number>

 


 

Troubleshooting

 

  • Check Status of Pods.

  • Check Logs of Pods/Containers.

  • Check Service Port Status.

  • Check requirements/dependencies of application.

 


 

How Can XenonStack Help You?

 

Our DevOps Consulting Services provides DevOps Assessment and Audit of your existing Infrastructure, Development Environment and Integration.

 

Our DevOps Professional Services includes - 

 

Continuous Integration & Continuous Deployment

 

Enable Secure Continuous Integration and Continuous Delivery Pipeline with Jenkins/Bamboo/TeamCity for delivery, automation, self-service environment, and On-demand. Deploy Java Application to production by decreasing the time by the automation of entire delivery pipeline comprising build, deploy, test, and release.

 

Microservices Architecture

 

Take a cloud-native approach to building Enterprise Applications for Web and Mobile with a Microservices Architecture. Run each service inside a container and combine all those containers to form a complex Microservices Application.

 

Cloud Infrastructure Services

 

Develop, Deploy and Manage your Java Application on leading Cloud Service Providers - AWS, Microsoft Azure, Google Cloud, and Container Environment - Kubernetes and Docker.

 

Serverless Computing

 

Build and run your applications and services without thinking about the servers with XenonStack Serverless Computing Services. Serverless Computing offers No Server Management, Flexible Scaling, High Availability, No Idle Capacity.

 

Ready To Discuss Your Requirements Request Free Consultation



Share Post On Social Media

Related Posts


Sign up

AND STAY UPDATED!

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

NexaStack - DevOps & Serverless Computing Platform

Elixir Data - Modern Data Integration Platform

Contact For Free Assessment

Chat With Our Experts

Contact Us

Your Information Submitted Successfully!