DevOps(Day-85): Project-6
Table of contents
Aim
The project involves deploying a Node JS app on AWS ECS Fargate and AWS ECR.
Pre-requisite
Writing a Dockerfile
Building AWS EC2 instance.
Project Steps
Cloning the source code from GitHub
- Let's go to the GitHub repository and copy the source code URL.
https://github.com/biswarajsahoo111/node-todo-cicd.git
Create an EC2 instance in AWS management console. Navigate to the EC2 instance.
Clone the repository from GitHub to the EC2 instance.
Configuring image in AWS ECR
Create a repository. I have selected the public repository and the repo name.
Select all the operating systems and versions according to the OS of Fargate you would select. Finally, create the repository.
Now, you can check the public repository for the created repository.
Configuring IAM
Create an IAM user in the AWS management console.
Install the awscli in the AWS EC2 instance.
Connect the EC2 instance with AWS management console through awscli.
Pushing the image to ECR0
Navigate to the AWS ECR and view the push commands.
- Earlier, we had pushed the image to DockerHub in my previous blogs. The steps and concepts are similar but the platform differs. Generally in IT industry ECR is used as an image registry.
Execute commands 1 and 2 in the EC2 instance.
Command 1: This will take the ecr token and provide to docker for the connection to the repository.
Command 2: This will build the image from the Dockerfile.
Execute commands 3 and 4 in EC2 instance.
Command 3: This tags the image that we have built using docker.
Command 4: This command will push the image from EC2 instance to ECR.
After the image push, you can check the ECR for the image.
Configuring AWS ECS
- Navigate to the ECS repository in the AWS console.
Create a cluster in ECS.
Provide the Cluster name, VPC and subnet you want your application to be available on.
Using AWS Fargate
One of the major disadvantages of using AWS EC2 for an application is we have to create multiple instances in case of an application load increase that will have a cost impact.
To avoid this, we will use AWS Fargate which is a serverless technique of providing the specification of applications that will be automatically managed without spinning off any instance.
- Therefore, we will select AWS Fargate fo the cluster to run on.
The cluster is now ready!!!
We used to run docker run to create a container in the EC2 instance out of the docker image. That was nothing but a task. Therefore let's create a task definition for our cluster.
Provide the task name, Container image details and ports for the application to be run on. We must have exposed a port in our Dockerfile.
Select the CPU and memory configuration according to the application load.
Let the rest be default and click on next.
Review the details and create the task.
Now, the task is finally created!!!!
Click on deploy and then Run task to run the task on the cluster we had created.
Choose the cluster. Select the launch type to be Fargate
Now click to create.
The task is now deployed to the cluster.
Open port in the security group.
Navigate to the ENI ID in the task.
Go to the security group URL.
Navigate to the Inbound rule in the security group and open the Port 80 which is HTTP and select my IP to have access for myself.
-
Project live execution
-
Navigate to the task that we created. Take the public IP.
We can see our application is live!!!!!!!
Thanks for reading my article. Have a nice day.
WRITTEN BY Biswaraj Sahoo --r | DevOps Engineer | Docker | Linux | Jenkins | AWS | Git | Terraform | Docker | kubernetes
Empowering communities via open source and education. Connect with me over linktree: linktr.ee/biswaraj333
Subscribe to my newsletter
Read articles from Biswaraj Sahoo directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Biswaraj Sahoo
Biswaraj Sahoo
--AWS Community Builder | DevOps Engineer | Docker | Linux | Jenkins | AWS | Git | Terraform | Docker | kubernetes Empowering communities via open source and education.