XenonStack

A Stack Innovator

Post Top Ad

Wednesday 28 February 2018

2/28/2018 03:09:00 pm

Deploying Python Application on Docker & Kubernetes

Blog Single Post Image

 Overview

 In this post, We’ll share the process how you can Develop and Deploy Python Application using Docker and Kubernetes and adopt DevOps in existing Python Applications.

Prerequisites are mentioned below

 To follow this guide you need 

Kubernetes is an open source platform that automates container operations, and Minikube is best for testing kubernetes in a local environment.

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 is permanent storage that we attach to the kubernetes container. We will be using cephfs as a persistent data store for kubernetes container applications.

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

Dockerfile contains all the actions that are performed to build python application.

The Registry is an online image store for container images.

Below mentioned options are few most popular registries.

2. AWS ECR

Dockerfile

The Below mentioned code is sample docker file for Python applications. In which we are using python 2.7 development environment.
FROM python:2.7
MAINTAINER XenonStack

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

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

# Installing python dependencies
COPY requirements.txt /usr/src/app/
RUN pip install --no-cache-dir -r requirements.txt

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

# Application Environment variables
ENV APP_ENV development

# Exposing Ports
EXPOSE 5035

# Setting Persistent data
VOLUME ["/app-data"]

# Running Python Application
CMD ["python", "wsgi.py"]


Building Python Docker Image


 The Below mentioned command will build your application container image. 
$ docker build -t <name of your python application>:<version of application> .





Publishing Container Image

To publish Python container image, we can use different private/public cloud repository like Docker HubAWS ECRGoogle Container RegistryPrivate Docker Registry.

  • Adding Container Registry to Docker Daemon
If you are using docker registry other than docker hub to store images, then we need to add that container registry to our local docker daemon and kubernetes Docker daemons.

Continue Reading:XenonStack/Blog

Tuesday 20 February 2018

2/20/2018 01:08:00 pm

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>
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.
$ docker login
Now we need to retag java application image and push them to docker hub container registry.
To Retag application container image
$ docker tag <name of your application>:<version of your application>   <your docker hub account >/<name of your repository >:<version of your application>
To Push application container Images
$ docker push <your docker account >/<name of your repository >:<version of your application>
Similarly, we can push images to any of above-mentioned container registry like Docker Hub, AWS ECR, Google Container Registry, Private Docker Registry etc.

Continue Reading: XenonStack/Blog


Tuesday 13 February 2018

2/13/2018 12:41:00 pm

Deploying Kotlin Application on Docker & Kubernetes

Blog Single Post 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.

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.

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 ["/kotlin-data"]
# Exposing Port
EXPOSE 8082
# Running Kotlin Application
CMD ["java", "-jar", "target/<name of your kotlin jar>.jar"]

Building Kotlin Application Image


The below mentioned command will build your application container image.

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

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

$ docker tag <name of your application>:<version of your application> <your docker hub account >/<name of your repository >:<version of your application>

To Push application container Images

$ docker push <your docker account >/<name of your repository >:<version of your application>

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.

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: <name of application>
namespace: <namespace of Kubernetes>
spec:
replicas: 1
template:
metadata:
labels:
k8s-app: <name of application>
spec:
containers:
- name: <name of application>
image: <image name >:<version tag>
imagePullPolicy: "IfNotPresent"
ports:
- containerPort: 8082
volumeMounts:
- mountPath: /kotlin-data
name: <name of application>
volumes:
- name: <name of application>
emptyDir: {}

  • Service File

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

apiVersion: v1
kind: Service
metadata:
labels:
k8s-app: <name of application>
name: <name of application>
namespace: <namespace of Kubernetes>
spec:
type: NodePort
ports:
- port: 7102
selector:
k8s-app: <name of 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.

$ kubectl create -f <name of application>.deployment.yml
$ kubectl create -f <name of application>.service.yml

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.
  
$ kubectl get po --namespace=<namespace of kubernetes> | grep <application name>

Result of above command

< name of your application >-1349584344-uah2u 1/1 Running 0 22d 10.233.84.18 k8-master


Continue Reading:XenonStack/Blog