AWS : 

Amazon Web Services (AWS) is Amazon’s cloud web hosting platform that offers flexible, reliable, scalable, easy-to-use, and cost-effective solutions.

There are different types of services which AWS exposes and they are categorized by Compute, Storage, Database, Analytics etc.

Compute Services :

EC2 instance is the basic service under Compute. EC2 instance doesn’t come with any container services and users has the option of selecting software (linux vs windows etc). Installation of required softwares can be done on this instance.

Elastic Container Service is an other Compute service. Selecting this will install certain container services exposed as a package

Storage Services:

We have Storage Services such as S3 (All files , pdfs , static content can be stored here . Other services in this category include EFS, Glacier, Storage Gateway

Database Services: 

Dynamo DB , Elastic cache are examples of few Database services exposed. The entire database will be created and we can configure datasource , username/password , connection pooling. In short with little effort AWS will create the database server and take care of maintaining for us.

SnapShot: 

We can create snapshot of the current version of the instance so that we can create an instance from the snapshot. As an example we install all the required softwares on the instance and complete the work .We are not interested in keeping the system when we are not using it and hence we decommission the instance but we need all the configurations made at a later point of time (say 2 months). With the snapshot, we can actually get back all the configurations and environment set up is done with out much effort.

Why Docker/Containerization ? 

Scenario: Let us have a usecase where we have 1 EC2 instance and our objective is to run a java application (running on Tomcat with Java 8) and an other java application (running on Jboss with java 6) .

In good olden days , to solve this we create 2 virtual machines and install Tomcat – Java 8 on Virtual machine 1 and Jboss – Java 6 on Virtual machine 2. The problem with this approach is that too many resources get unused and we are wasting lot of hardware resources.

Solution with AWS with out Docker : We can actually install Tomcat, Jboss, Java 8 & Java 6 on EC2 instance but we have to manually configure classpath , virtual memory size etc. There are chances that Tomcat application may be heavily used and it may cause other application on Jboss running relatively slower.

A clean solution to address this usecase is by Docker . Here we partition EC2 with containers . They share the same hardware, kernel but run time environment will be different. We can install Tomcat – Java 8 on container 1 and Jboss – Java 6 on container 2. This way each application is running in its own containers under the same EC2 instance .

Docker File , Image ? 

Docker file is a human written file and it has set up instruction and what needs to be done such as 1. Install Java 8 version 2) Install Tomcat 3) Copy the jar from location 4) execute the jar. This file will be part of code base and checked into git.

Docker needs to be installed on the EC2 instance so that we can create image and later execute/run the image.

Docker commands :

  • docker build – Builds an image form a Docker file
  • docker push – Pushes an image or a repository to a registry
  • docker pull – Pulls an image or a repository from a registry
  • docker start – Starts one or more stopped containers
  • docker stop – Stops one or more running containers

Why Kubernetes ? 

Take a scenario we have 2 microservices – MicroService A and MicroService B. We need to create 3 instances of MicroService A and 2 instances of MicroService B. How can we do this ?

With Docker we can create Docker File 1 for MicroService A and Docker File 2 for MicroService B . Eventually Docker Image 1 , Docker Image 2 gets created. By executing Docker Image 1 – 3 times , 3 instances of Microservice A gets created in 3 containers. Similarly by executing Docker Image 2 – 2 times , 2 instances of Microservice B gets created.

Problem ? If we have to scale up or scale down the instances dynamically  , how can we do this?

Kubernetes solves this problem by taking care of managing the Microservices and it takes care of load balancing , creating containers (run times for instances ) etc .

Kubernetes needs to be installed on EC2 instance first and using kubectl commands we can run the docker image. Here we can specify how many number of instances of MicroService A to be created – Here its 3 . Kubernetes does it for us and it manages all the instances.

Real time Production : 

In real time say we have 3 EC2 Instances and we have 3 MicroServices

MicroServiceA  – need 10 instances ,MicroService B  – need 5 instances , MicroService c – need 3 instances.

In all 3 EC2 instances , we install Kubernetes . We can treat this as a 3 node Kubernetes cluster with 1 master and 2 child nodes. Now we leave the job for kubernetes to decide where microservice instances run.

As an example here 1st EC2 Instance  can have 3 instances of MicroSevice A , 2nd EC2 Instance can have 3 instances of Microservice A and 3rd EC2 Instance can have 4 instances of MicroService A. In short all 10 get distributed among the available EC2 Kubernetes machines.

Other Possible Solutions :

Instead of Kubernetes we can solve the problem with Eurekha Naming Server , Spring Cloud Config server where they made configurations of microservice instances.