XenonStack - A Stack Innovator

Deploying Kotlin Application on Docker & Kubernetes

by Gursimran | May 19, 2017 |  Categories -  Microservices, Kotlin, Kubernetes, Docker

Blog Image

 

Overview

 

In this post, We’ll show how you can launch Kotlin Application in Kubernetes. 

 

Kotlin is a new programming language from JetBrains. It first appeared in 2011 when JetBrains unveiled their project named “Kotlin”. Kotlin is an Open-Source Language.

 

Basically like Java, C and C++ - Kotlin is also “statically typed programming language”. Statically typed programming languages are those languages in which variables need not be defined before they are used.

 

To know more about Kotlin Language, you may Love to read our Blog Overview of Kotlin Language & Comparison Between Kotlin & Java

 

Prerequisites

 

To follow this guide you need

 

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

 

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

 

  • Shared Persistent Storage - 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 a persistent data store for Kubernetes container applications.

 

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

 

  • Dockerfile - Dockerfile contains a bunch of commands to build Kotlin application.

 

  • Container-Registry - The Container Registry is an online image store for container images.

 

Below mentioned options are few most popular registries.

 

 

Create a Dockerfile

 

The below mentioned code is sample dockerfile for Kotlin applications. In which we are using maven 3 as a builder for Kotlin applications and OpenJDK 8 as a base development environment. Alpine Linux is used due to its very compact size.

 

 

Building Kotlin Application Image

 

The below mentioned command will build your application container image.

 

 

Publishing Container Image

 

Now we publish our Kotlin 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 an account on Docker Hub and create a Public/Private Repository of you application name.

 

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

 

 

Now we need to retag Kotlin 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.

 

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 Kotlin Application on Kubernetes

 

Kotlin Application Container 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 Kotlin Application on Kubernetes.

 

Verification

 

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

 

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

 

 

Result of above command

 

 

Testing

 

Get the External Node Port using the below-mentioned command. External Node Port are 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>

 

Application Scaling

 

Your Kotlin application should be a stateless application before your application scaling.

 

You can scale out an application by so many ways.Here I have mentioned two of them which are mostly used.

 

  • Kubectl

 

kubectl scale --current-replicas=1 --replicas=3 deployment/<name of your application>

 

  • Kubernetes Dashboard

 

Update your deployment from kubernetes dashboard

 

Troubleshooting

 

  • Check Status of Pods.

  • Check Logs of Pods/Containers.

  • Check Service Port Status.

  • Check requirements/dependencies of application.

 

Summary

 

At XenonStack we have specialized professionals that can help you in starting with Microservices Architecture, NoSQL and SQL Database, Docker & Kubernetes. Reach Us for Development, Deployment, and Consulting for MicroServices, Kubernetes, and Docker Technology Solutions.  

 

XenonStack Offerings

 

XenonStack is a leading Software Company in Product Development and Solution Provider for DevOps, Big Data Integration, Real Time Analytics & Data Science.

 

Product NexaStack - Unified DevOps Platform Provides monitoring of Kubernetes, Docker, OpenStack infrastructure, Big Data Infrastructure and uses advanced machine learning techniques for Log Mining and Log Analytics.

 

Product ElixirData - Modern Data Integration Platform Enables enterprises and Different agencies for Log Analytics and Log Mining. 

 

Product Akira.AI is an Automated & Knowledge Drive Artificial Intelligence Platform that enables you to automate the Infrastructure to train and deploy Deep Learning Models on Public Cloud as well as On-Premises. 

 

Get 1 Hour Free Assessment for DevOps, Big Data Strategy, and Data Science. CONTACT US NOW



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!