4.1. Docker/Kubernetes

Docker/Kubernetes Deployment Overview

This topic describes how to build an iWay application for deployment through Docker/Kubernetes.

This application consists of two Docker containers:

  1. iWay Application exposing an API (defined via RAML file) which utilized the iIT MongoDB Connector
  2. MongoDB Server

We brought these containers up and managed communication between two by using Docker and Kubernetes technology.

Docker is the world's leading containerization platform

Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications.

I. How to use iIT to build and run an iSM container

Install Docker for Windows Edge

It will prompt you to make sure HyperV and Containers are enabled.

  • This will require a reboot
  • This took a long time

After Reboot Go to the task menu and type in Docker.

  • You will see a Docker App.
  • This must be run as an Administrator
  • The Whale will show up in the Task bar
  • Right mouse click on the Whale and select the menu item settings.
  • Go to General
  • Click on Expose daemon without TLS

Bring up a Command Prompt

Type in some commands:

  • docker version
  • docker run hello-world
  • docker images

Create a sample Application Project with Docker and Kubernetes support.

Create New Application

Click Next. The Use Maven dialog opens, as shown in the following image.

Specify Maven Settings

Click Next. The Application Deployment dialog opens, as shown in the following image.

Specify Deployment Name

Click Finish.

Import the sample API application that is provided.

Import Project

The application consists of two Docker containers:

  1. iWay Application exposing an API(defined via RAML file) which utilized the iIT MongoDB Connector
  2. MongoDB Server

This application has several APIs:

Application APIs

For example  /companies/POST execute the following process flow with the MongoDB connector:

MongoDB Process Flow

The Dockerfile is essentially the build instructions to build the image. The advantage of a Dockerfile over just storing the binary image (or a snapshot / template in other virtualization systems) is that the automatic builds will ensure you have the latest version available.

Docker File

Bundle

Runs a sample application : package -P docker-image

Run Sample Application

You should be able to build a docker image iway:latest:

Build Docker Image

Now it is time to open a Docker Explorer to see this image.

Windows-->Show views--> Other-->Docker-->Docker Explorer

Open Docker Explorer

You have to provide TCP Connection URI:  http://127.0.0.1:2375

Docker TCP Connection Properties

Docker Explorer has 2 folders: Container and Images

Docker Explorer Folders

Right click the image-->Show in-->Properties give you detailed image information:

Docker Properties

Now you may run this image as a container.

Right click --> Run.

Provide a name of the container and click Finish:

Docker Container Settings

Should see the following :

Console tab

Go to Containers folder, refresh it and on the expand the demo container:

demo container

On port 9999, right button click -->Show in-->Browser you should see the console of the running application (there is no Registry menu any more)

iSM Administration Console

This is the image that was build from the sample application and pushed into the Docker Hub.

Docker Hub is a registry service on the cloud that allows you to download Docker images that are built by other communities.

You can also upload your own Docker built images to Docker Hub.

Docker Hub

This image will be used in Docker compose, kubernetes, AWS Cloud, Azure Cloud and Google Cloud iWay deployment.

II . Docker Compose Deployment

You may use my image or build your own…then change the as docker-compose.yml file accordingly

  1. Install docker-compose for windows
  2. Create a new empty file docker-compose.yml and copy into it the following:
    version: '2'
    networks:
      app-tier:
        driver: bridge
    services:
      mongodb:
        image: 'iwaydocker/iwaydemo:latest'
        ports:
          - "27017:27017" 
        volumes:
          - .:/iwaymongo 
        networks:
          - app-tier
      myapp:
        image: 'iway:latest'
        links:
          - mongodb
        ports:
          - "9999:9999"
          - "8081:8081"
          - "9000:9000"
          - "9001:9001"
        networks:
          - app-tier
  3. Copy the docker-compose.yml in the directory where it installed or add docker-compose.exe it to the path5.Use a sample iIT project provided
  4. Build the bundle
  5. Build the image package –P docker-image
  6. Run command: docker compose up -d
  7. Should start 2 containers
  8. Go to http://localhost:8081/companies/ end point

III. Kubernetes deployment

Create a new empty file deployment.yml and copy into it the following:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
 name: myiway
 labels:
 app: myiway
spec:
 replicas: 1
 strategy: {}
 template:
 metadata:
 labels:
 app: myiway
 spec:
 containers:
 - image: iwaydocker/iwaydemo
 imagePullPolicy: Always
 name: myiway
 ports:
 - containerPort: 9999
 - containerPort: 9000
 - containerPort: 9001
 - containerPort: 8081
 resources: {}
 restartPolicy: Always
status: {}

Create a new empty file mongodb-deployment.yml and copy into it the following:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: C:\Program Files\docker\kompose-windows-amd64.exe convert -f docker-compose.yml
    kompose.version: 1.12.0 (0ab07be)
  creationTimestamp: null
  labels:
    io.kompose.service: mongodb
  name: mongodb
spec:
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: mongodb
    spec:
      containers:
      - image: bitnami/mongodb:latest
        name: mongodb
        ports:
        - containerPort: 27017
        resources: {}
        volumeMounts:
        - mountPath: /data/db
          name: slow
      restartPolicy: Always
      volumes:
      - name: slow
        persistentVolumeClaim:
          claimName: slow
status: {}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  creationTimestamp: null
  labels:
    io.kompose.service: mongodb-claim0
  name: mongodb-claim0
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 100Mi
status: {}

Run the following kubernetes commands:

  • kubectl create -f deployment.yml
  • kubectl create -f mongodb-deployment.yml
  • kubectl expose deployment myiway --name=myiway --type=LoadBalancer
  • kubectl expose deployment mongodb --name=mongodb --type=LoadBalancer

To check if everything is OK , you may run the following commands :

kubectl describe pods

Describe Pods Command

kubectl get services:

Get Services Command

How to scale kubernetes  application:

Let's scale the Deployment to 2 replicas. We'll use the kubectl scale command, followed by the deployment type, name and desired number of instances:

  1. kubectl get deployments

    NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE

    mongodb   1                    1                      1                      1               3d

    myiway      1                    1                      1                      1               3d

  2. kubectl scale deployments/myiway --replicas=2
  3. kubectl scale deployments/mongodb --replicas=2
  4. kubectl get deployments

    Get Deployments Command

  5. kubectl get pods -o wide

Get Pods Command

You may want to show a kubernetes Dashboard where all Deployments, Pods, Replica sets displayed and user may drill down on those resources

  1. kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml>pre>
  2. kubectl proxy

Kubectl will handle authentication with apiserver and make Dashboard available at http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/.

Kubernetes Dashboard

IV. How to test iway demo application using Fiddler, you may use Postman etc.

  1. POST - add new document
    {
      "name" : "iWay Software",
      "tags" : [ "IT", "computer", "maintenance", "software" ],
      "address" : {
        "street" : "2 Penn Plaza",
        "zipcode" : "10121",
        "city" : "NY"
      }
    }

    POST Request

  2. GET - retrieve a document(s)

    GET Request

    GET Response

  3. PUT - update the document by ID (take company ID from the GET call). Result – name property of the company got updated.

    PUT Request

    PUT Response

  4. GET - retrieve a document by Company ID

    GET Document

  5. DELETE - delete a document by Company ID

    DELETE Document