Day85 (DevOps) -Project-6

Day85 (DevOps) -Project-6

Project Description

The project involves deploying a Node JS app on AWS ECS(Cluster/container orchestration) Fargate and AWS ECR(Registry can say Dockerhub for AWS)

Setup an ECS cluster

Code availability:https://github.com/gsbarure/node-todo-cicd.git

Step1:Launch an EC2 instance

git clone -https://github.com/gsbarure/node-todo-cicd.git

Step2:Setup AWS CLI and AWS Login in order to tag and push to ECR

sudo apt-get install awscli and check version if gets installed or not.

Step3:Create IAM user with all required permissions

Configure AWS with access key: command/ aws configure

aws configure and put access key and secret key

Step5:Once you are done with above step,

Move to ECR:

ECR is an acronym for the “Elastic container registry”. In simple terms, it is the so-called “AMAZON DOCKER HUB” of your containers!

You can push all your local containers images from your LOCAL to ECR, ECR is the home for all your pushed container images where later it can be used by ECS service to get deployed on AMAZON platform!

Here are the execution steps:

Create repo-

Step6:Issue below commands to push your image from local to ECR

Image tagged

docker images

docker push i.e.pushing to AWS ECR

Now, image has pushed to ECR

You can verify the status if reflected in ECR or not!

Step7:ECS(Amazon Elastic Container Service)

CLUSTER: ECS cluster is a regional grouping of one or more container instances on which you can run task requests.When an instance launches, the ECS-agent software on the server registers the instance to an ECS Cluster. You can choose an existing VPC, or create a new one to spin up your container instances.

TASK DEFINITION: It is the complete definition of your tasks(in simple terms, your containers) and to describe how containers should be provisioned. Here You need to provide a link to ECR’s saved container images, CPU units, Memory, Container ports to expose, network type and many more. Simple terms, you are defining your containers and how to launch them via Task definitions.

TASKS: It is nothing but “ A RUNNING CONTAINER “. The description you provided for your containers in TASK DEFINITION, TASKS are the result of that. It can be thought of as a “RUNNING INSTANCE” of a Task Definition.(you can create service also under deploy option)

AWS Fargate is a technology that you can use with Amazon ECS to run containers without having to manage servers or clusters of Amazon EC2 instances. With Fargate, you no longer have to provision, configure, or scale clusters of virtual machines to run containers. This removes the need to choose server types, decide when to scale your clusters, or optimize cluster packing.

When you run your Amazon ECS tasks and services with the Fargate launch type or a Fargate capacity provider, you package your application in containers, specify the Operating System, CPU and memory requirements, define networking and IAM policies, and launch the application. Each Fargate task has its own isolation boundary and does not share the underlying kernel, CPU resources, memory resources, or elastic network interface with another task.

Cloudformation Template for the ECS cluster which we have created.

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Description": "The template used to create an ECS Cluster from the ECS Console.",
  "Parameters": {
    "ECSClusterName": {
      "Type": "String",
      "Description": "Specifies the ECS Cluster Name with which the resources would be associated",
      "Default": "NodeJs-todo-application"
    },
    "VpcId": {
      "Type": "String",
      "Description": "Optional - Specifies the ID of an existing VPC in which to launch your container instances. If you specify a VPC ID, you must specify a list of existing subnets in that VPC. If you do not specify a VPC ID, a new VPC is created with at least 1 subnet.",
      "Default": "",
      "AllowedPattern": "^(?:vpc-[0-9a-f]{8,17}|)$",
      "ConstraintDescription": "VPC Id must begin with 'vpc-' and have a valid uuid"
    },
    "SubnetIds": {
      "Type": "CommaDelimitedList",
      "Description": "Optional - Specifies the Comma separated list of existing VPC Subnet Ids where ECS instances will run",
      "Default": ""
    }
  },
  "Resources": {
    "ECSCluster": {
      "Type": "AWS::ECS::Cluster",
      "Properties": {
        "ClusterName": {
          "Ref": "ECSClusterName"
        },
        "CapacityProviders": [
          "FARGATE",
          "FARGATE_SPOT"
        ],
        "ClusterSettings": [
          {
            "Name": "containerInsights",
            "Value": "disabled"
          }
        ],
        "Configuration": {
          "ExecuteCommandConfiguration": {
            "Logging": "DEFAULT"
          }
        },
        "ServiceConnectDefaults": {
          "Namespace": "NodeJs-todo-application"
        },
        "Tags": []
      }
    }
  },
  "Outputs": {
    "ECSCluster": {
      "Description": "The created cluster.",
      "Value": {
        "Ref": "ECSCluster"
      }
    }
  }

Here is your cluster,

Step8:

Create a new task definition and describe everything about your container. Including the network type, ECR’s saved image path that you pushed from your local to Amazon ECR. Provide memory, CPU units and expose ports.

Step9:So,Run task now!

A task is the instantiation of a task definition within a cluster. After you create a task definition for your application within Amazon ECS, you can specify the number of tasks to run on your cluster. An Amazon ECS service runs and maintains your desired number of tasks simultaneously in an Amazon ECS cluster.

Once you are done with Run task, click on running task search for ENI ID and open port under SG on which your app is running!(FYI:not your instance port as we selected fargate)

Step10:Here you go and access your app over public ip!

Code availability(GitHub):https://github.com/gsbarure/node-todo-cicd.git

Linkdin:https://www.linkedin.com/in/gajanan-barure-7351a4140

***Happy Learning :)***✌✌

Keep learning,Keep growing🎇🎇

Thank you for reading!! Hope you find this helpful.

#day85#90daysofdevops#devopscommunity#

Shubham Londhe