XenonStack

A Stack Innovator

Post Top Ad

Tuesday 27 March 2018

Deploying Microservices Based Java Application on Docker & Kubernetes

Blog Single Post Image

Overview

Running Containers at any real-world scale requires container orchestration and scheduling platform like Docker SwarmApache 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.
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.
FROM maven:3-alpine

MAINTAINER XenonStack

# Creating Application Source Code Directory
RUN mkdir -p /usr/src/app

# Setting Home Directory for containers
WORKDIR /usr/src/app

# Copying src code to Container
COPY . /usr/src/app

# Building From Source Code
RUN mvn clean package

# Setting Persistent drive
VOLUME ["/data"]

# Exposing Port
EXPOSE 7102

# Running Java Application
CMD ["java", "-jar", "target/<name of your jar>.jar"]

Building Java Application Image

$ docker build -t <name of your java application>:<version of application>


Continue Reading:XenonStack/Blog

No comments:

Post a Comment