Loading....

How-to-Deploy-Java-Microservices-on-Amazon-ECS-with-AWS-Fargate-Two-Approaches-1

Introduction

When you decide to deploy microservices on Amazon ECS, you will have to use AWS Fargate. The advantage of using AWS Fargate is that it offers scalability along with flexibility for your containerized applications. In order to deploy the Java microservices on ECS using Fargate, we will be taking help of the following two approaches.

  • Using Docker images from Docker hub
  • Using Elastic Container Registry

Approach 1: Docker Hub Deployment

Prerequisites

Architecture

Source Technology Stack

  • The source technology stack includes deployment of Java microservices implemented in Spring Boot framework.

Source Architecture

  • The client sends request to On-premises Docker
  • The requests include GET, PUT, POST and DELETE
  • Docker sends the response in JSON format back to the client

Target Technology Stack

  • Amazon ECS cluster is responsible for hosting the microservices with Fargate
  • VPC must be used for ECS cluster along with all the associated security groups

Target Architecture

  • AWS Fargate service within Amazon ECS contains all the running tasks
  • Protected by Subnet, the request sent by the client is handled accordingly
  •  If the sent request is successfully accepted, then the response is sent back in the form of JSON 

Tools

  • Amazon ECS removes the need of manual scaling and container orchestration
  • AWS Fargate will run the containers without the management of servers
  • Docker is used for the containerization i.e. building, testing and deploying applications in a containerized form

Dockerfile

FROM openjdk:11penjdk:11

ADD target/Spring-docker.jar Spring-docker.jar

EXPOSE 8080

ENTRYPOINT ["java","-jar","Spring-docker.jar"]

Epics

Creating New Task Definitions

  • Create a task definition in the ECS console
  • You should possess the skills of an AWS system administrator along with app developer
  • Steps
    • Open ECS console
    • Go to the Task Definitions
    • Create a New Task Definition
    • Choose the launch type as Fargate
    • Configure the things like task name, CPU and memory
    • Defining the container will include details about Docker image, port mappings and memory limits
    • At last, create the task

Configure the Cluster

  • Create and configure an ECS cluster
  • You should possess the skills of an AWS system administrator along with app developer
  • Steps
    • Select cluster type as Networking Only
    • Configure the name of the cluster according to your choice
    • Create the cluster
    • Along with this, create and update the security groups
    • Configure public IP settings, subnets and VPC

Run the Task

  • Now it is time to run the configured task in the cluster
  • You should possess the skills of an AWS system administrator along with app developer
  • Steps
    • Select Run New Task option present inside the cluster
    • Select launch type as Fargate
    • Select the following: revision, task definition, cluster and platform version
    • Now specify the optional task group and number of tasks
    • Configure public IP settings, security groups, VPC and subnets
    • Confirm the settings
    • Run the task
  • Cut Over
    • It is important to test the working of the application after its deployment
    • You should possess the skills of an AWS system administrator along with app developer
  • Steps
    • The running task will have the application’s URL, copy it
    • Go to your browser and enter the public IP in order to test the application
  • Related Resources

Approach 2: Amazon ECR and Fargate Deployment

Prerequisites

Architecture

Source Technology Stack

  • You should have Java microservices developed using Spring Boot framework
  • These microservices should be deployed On-Premises with Docker

Source Architecture

  • The client sends request to On-premises Docker
  • The requests include GET, PUT, POST and DELETE
  • Docker sends the response in JSON format back to the client

Target Technology Stack

  • For managing Docker containers, use Amazon ECR service
  • Amazon ECS cluster should be compatible with Fargate

Target Architecture

Tools

  • Amazon ECR will be used for registry management like managing, storing and deploying container images from Docker
  • Amazon ECS will be used to provide a scalable container orchestration service that support Docker containers
  • AWS Fargate will serve the role of a compute engine for ECS. It will run the containers without actually managing the servers
  • Docker will be used for testing, building and delivering containerized applications

Dockerfile

FROM openjdk:8

ADD target/Spring-docker.jar Spring-docker.jar

EXPOSE 8080

ENTRYPOINT ["java","-jar","Spring-docker.jar"]

Epics

Creating an Amazon ECR Repository

  • Create a private repository in Amazon ECR
  • You should possess the skills of a developer along with a System Admin
  • Steps
    • Sign in to your AWS account using AWS Management Console
    • Go and open Amazon ECR console
    • Create a private repository from there
    • Start uploading the project using AWS CLI version 1.7 or newer
    • Copy the URL of your repository for future needs

Create and Spin Up the Container

  • For launch type choose Fargate
  • Configure the memory, task name, CPU along with this define the container by using ECR repository URL
  • Now finally create the task

Create an ECS Cluster and Configure a Service

Conclusion

All in all, if you want a robust solution for containerized applications then you have to deploy the Java microservices on Amazon ECS using AWS Fargate. It doesn’t matter which approach you use (pulling an image from Docker hub or using Amazon ECR), both of them will offer you ease in deployment, scalability and manageability. It is up to you which approach you use depending upon your requirements. Here is the detailed AWS Re-invent Talk on Deployment of microservices using AWS Fargate 

Leave a Reply

Your email address will not be published.