An open API service indexing awesome lists of open source software.

https://github.com/devopspradeepyadav/3-tier-architecture-application

3-Tier-Architecture-Application deployment
https://github.com/devopspradeepyadav/3-tier-architecture-application

Last synced: 8 months ago
JSON representation

3-Tier-Architecture-Application deployment

Awesome Lists containing this project

README

          

# **My Three-Tier Web Application Challenge**

## Overview

Welcome to my **Three-Tier Web Application** challenge! This project is about deploying scalable and robust applications on AWS using **ReactJS**, **NodeJS**, and **MongoDB**. It's a full-stack app, with a backend API, a frontend React app, and a persistent MongoDB database, all running seamlessly on **AWS EKS (Elastic Kubernetes Service)**.

The goal is:

* Architect and deploy a Three-Tier Web Application
* Use modern DevOps tools and practices (Terraform, Jenkins, Kubernetes)
* Manage containerized applications in AWS using EKS
* Implement CI/CD pipelines for continuous integration and delivery
* Implement DevSecOps practices for security and vulnerablity testing (Trivy)

## **Tech Stack**

Here’s a quick rundown of the core technologies used in this project:

* **Frontend:** ReactJS
* **Backend:** Node.js (Express)
* **Database:** MongoDB
* **Deployment:** AWS EKS (Elastic Kubernetes Service)
* **CI/CD:** Jenkins & Terraform
* **Monitoring:** Prometheus & Grafana
* **GitOps:** ArgoCD
* **Containerization:** Docker
* **Cloud Services:** AWS (EC2, ECR, IAM, ALB)

![Three-Tier Web Application](assets/Three-Tier.gif)

---

## **Project Structure**

The repository contains the following key directories:

### **1. Application Code**

The `Application-Code` directory holds the source code for both the frontend and backend of the application. You’ll find:

* A **Node.js backend API** that handles CRUD operations for a **Todo app**.
* A **ReactJS frontend** that communicates with the backend API.

### **2. Jenkins Pipeline Code**

Inside the `Jenkins-Pipeline-Code` directory, you’ll find Jenkins pipeline scripts designed to automate the build, test, and deployment processes. These scripts ensure that any changes pushed to the repository go through a seamless CI/CD pipeline.

### **3. Jenkins Server Terraform**

The `Jenkins-Server-TF` directory contains Terraform scripts to deploy a **Jenkins Server** on AWS. This helps automate the deployment and scaling of Jenkins for CI/CD purposes.

### **4. Kubernetes Manifests Files**

This directory includes Kubernetes manifests required for deploying the app to **AWS EKS**. These manifests define the services, deployments, and ingress needed to run the application in a Kubernetes environment.

---

## **Project Details**

This project is a **full-stack cloud-native application** that:

* Runs the backend on **AWS EKS**.
* Utilizes **MongoDB** for data persistence.
* Incorporates a **ReactJS frontend** that interacts with the backend via REST APIs.
* Implements **CI/CD pipelines** using Jenkins for automated testing, building, and deploying.
* Uses **Terraform** to provision AWS infrastructure.

I’ve also incorporated **GitOps** with **ArgoCD** for efficient Kubernetes deployment management.

---

## **Why This Project?**

This project is a showcase of my ability to:

* Architect scalable web applications using modern tools and practices.
* Set up **CI/CD pipelines** that automate deployments and reduce manual effort.
* Work with **AWS services** like EKS, EC2, and ECR to create production-ready cloud infrastructure.
* Leverage **Kubernetes** for container orchestration and management at scale.

---

## **How to Run the Project**

### **Prerequisites**

Before you begin, you’ll need:

* An **AWS account** with the necessary permissions to provision EKS, EC2, and other AWS resources.
* Familiarity with **Docker**, **Kubernetes**, and **AWS**.
* **Terraform**, **kubectl**, **eksctl**, and **Jenkins** installed.

### **Steps to Set Up**

#### **1. IAM Configuration**

* Create an `eks-admin` IAM user with **AdministratorAccess** and generate **Access Keys**.

```bash
aws iam create-user --user-name eks-admin
aws iam attach-user-policy --user-name eks-admin --policy-arn arn:aws:iam::aws:policy/AdministratorAccess
```

#### **2. Provision EC2**

* Launch an **Ubuntu EC2 instance** on your preferred AWS region and SSH into it.

```bash
ssh -i your-key.pem ubuntu@your-ec2-public-ip
```

#### **3. Install Required Tools**

* Install **AWS CLI**, **Docker**, **kubectl**, and **eksctl** on your EC2 instance.

```bash
# Install AWS CLI
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
sudo apt install unzip
unzip awscliv2.zip
sudo ./aws/install -i /usr/local/aws-cli -b /usr/local/bin --update

# Configure AWS CLI
aws configure

# Install Docker
sudo apt-get update
sudo apt install docker.io
docker ps
sudo chown $USER /var/run/docker.sock

# Install kubectl
curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.19.6/2021-01-05/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin

# Install eksctl
curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/eksctl /usr/local/bin
```

#### **4. Set up EKS Cluster**

Use **eksctl** to create the EKS cluster and configure `kubectl` to interact with it.

```bash
eksctl create cluster --name three-tier-cluster --region us-west-2 --node-type t2.medium --nodes-min 2 --nodes-max 2
aws eks update-kubeconfig --region us-west-2 --name three-tier-cluster
kubectl get nodes
```

#### **5. Deploy the Application**

1. **Create Kubernetes Namespace**:

```bash
kubectl create namespace workshop
```

2. **Deploy the App**:
Apply the Kubernetes manifests to deploy the application.

```bash
kubectl apply -f kubernetes-manifests/
```

To delete the deployment:

```bash
kubectl delete -f kubernetes-manifests/
```

#### **6. Set up CI/CD Pipeline**

1. **Jenkins Pipeline**:
The Jenkins pipeline scripts are located in the `Jenkins-Pipeline-Code` directory. You can set up Jenkins to pull these scripts and automate the build and deployment process.

2. **Install Jenkins**:
If Jenkins is not already installed, use the following script to install it:

```bash
sudo apt update
sudo apt install openjdk-11-jdk
wget -q -O - https://pkg.jenkins.io/keys/jenkins.io.key | sudo tee /etc/apt/trusted.gpg
echo deb http://pkg.jenkins.io/debian/ / > sudo tee /etc/apt/sources.list.d/jenkins.list
sudo apt update
sudo apt install jenkins
```

3. **Configure Jenkins for CI/CD**:
Create and configure the Jenkins pipeline for the backend and frontend components using the scripts found in `Jenkins-Pipeline-Code`.

4. **Push Docker Images to ECR**:
Push the backend and frontend images to **AWS ECR** for deployment.

```bash
aws ecr create-repository --repository-name 3tierapp-backend
aws ecr create-repository --repository-name 3tierapp-frontend
```

#### **7. Install AWS Load Balancer**

1. **Create IAM Policy for Load Balancer**:

```bash
curl -O https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/v2.5.4/docs/install/iam_policy.json
aws iam create-policy --policy-name AWSLoadBalancerControllerIAMPolicy --policy-document file://iam_policy.json
```

2. **Deploy Load Balancer**:

```bash
eksctl utils associate-iam-oidc-provider --region=us-west-2 --cluster=three-tier-cluster --approve
eksctl create iamserviceaccount --cluster=three-tier-cluster --namespace=kube-system --name=aws-load-balancer-controller --role-name AmazonEKSLoadBalancerControllerRole --attach-policy-arn=arn:aws:iam::626072240565:policy/AWSLoadBalancerControllerIAMPolicy --approve --region=us-west-2
```

3. **Install AWS Load Balancer Controller**:

```bash
sudo snap install helm --classic
helm repo add eks https://aws.github.io/eks-charts
helm repo update eks
helm install aws-load-balancer-controller eks/aws-load-balancer-controller -n kube-system --set clusterName=three-tier-cluster --set serviceAccount.create=false --set serviceAccount.name=aws-load-balancer-controller
```

4. **Apply Load Balancer Configuration**:

```bash
kubectl apply -f full_stack_lb.yaml
```

#### **8. Cleanup**

* **Delete the EKS Cluster**:

```bash
eksctl delete cluster --name three-tier-cluster --region us-west-2
```

* **Clean up Resources**:

* Terminate the EC2 instance.
* Delete Load Balancer and associated