This application has 3 microservices, 2 for the backend and 1 for the frontend.
tree --filelimits 3 MERN_Microservices_EKS_Deployment/
MERN_Microservices_EKS_Deployment/
├── README.md
├── backend
│ ├── README.md
│ ├── helloService
│ └── profileService
└── frontend
- Set Up the AWS Environment
- 1.1 Set Up AWS CLI
- Prepare the MERN Application
- Version Control
- Continuous Integration with Jenkins
- Kubernetes (EKS) Deployment via HELM
- Monitoring and Logging
1: EC2 (min of 4Gb ram and 20 GB disk)
2: Install aws-cli in it
3: Jenkins installed in it
4: Install docker in it
5: Install EKSCTL in it
6: Install Kubectl in it
- Set Up AWS CLI on the EC2:
- Install AWS CLI and configure it with AWS credentials.
On your Ec2, run the aws configure --profile command to create an AWS CLI profile to use with git-remote-codecommit. When prompted, provide your AWS access key, your secret access key, the AWS Region where you created your AWS CodeCommit repository, and the default output format you prefer. For example:
% aws configure --profile demo-profile AWS Access Key ID [None]: *************** AWS Secret Access Key [None]: *************** Default region name [None]: ap-south-1 Default output format [None]:
- Install AWS CLI and configure it with AWS credentials.
On your Ec2, run the aws configure --profile command to create an AWS CLI profile to use with git-remote-codecommit. When prompted, provide your AWS access key, your secret access key, the AWS Region where you created your AWS CodeCommit repository, and the default output format you prefer. For example:
-
Containerize the MERN Application:
-
Ensure the MERN application is containerized using Docker. Create a Dockerfile for each component (frontend and backend).
For Backend Microservice https://github.com/AdarshIITDH/MERN_Microservices_EKS_Deployment/blob/main/backend/README.md
For Frontend Microservice https://github.com/AdarshIITDH/MERN_Microservices_EKS_Deployment/tree/main/frontend
-
-
Push Docker Images to Amazon ECR:
-
Build Docker images for the frontend and backend.
-
Create an Amazon ECR repository for each image.
-
Push the Docker images to their respective ECR repositories.
Hello Microservice: https://gallery.ecr.aws/c3w1m1q2/hello_service_adarsh
Profile Microservice: https://gallery.ecr.aws/c3w1m1q2/profile_service_adarsh
Frontend Microservice: https://gallery.ecr.aws/c3w1m1q2/frontend_service_adarsh
-
-
Use AWS CodeCommit:
-
Create a CodeCommit repository.
Now install the git-remote-codecommit in the EC2
apt install python3-pip pip install git-remote-codecommit
-
Push the MERN application source code to the CodeCommit repository.
Now clone the codecommit repo to the ec2
git clone codecommit::ap-south-1://adarsh_Microservice_Repo
-
-
Create Jenkins Jobs:
-
Create Jenkins jobs for building and pushing Docker images to ECR.
-
Trigger the Jenkins jobs whenever there's a new commit in the CodeCommit repository.
-
-
Create EKS Cluster:
- Use eksctl or other tools to create an Amazon EKS cluster.
Installing EKSCTL on EC2 using https://eksctl.io/installation/
# for ARM systems, set ARCH to: `arm64`, `armv6` or `armv7` ARCH=amd64 PLATFORM=$(uname -s)_$ARCH curl -sLO "https://github.com/eksctl-io/eksctl/releases/latest/download/eksctl_$PLATFORM.tar.gz" # (Optional) Verify checksum curl -sL "https://github.com/eksctl-io/eksctl/releases/latest/download/eksctl_checksums.txt" | grep $PLATFORM | sha256sum --check tar -xzf eksctl_$PLATFORM.tar.gz -C /tmp && rm eksctl_$PLATFORM.tar.gz sudo mv /tmp/eksctl /usr/local/bin
eksctl create cluster --name mern_microservice_adarsh --region ap-south-1 --nodegroup-name standard-workers --node-type t2.micro --nodes 2 --nodes-min 1 --nodes-max 3
aws eks --region ap-south-1 update-kubeconfig --name mern-microservice-adarsh
Now install kubectl to interact with the cluster [https://docs.aws.amazon.com/eks/latest/userguide/install-kubectl.html]
curl -O https://s3.us-west-2.amazonaws.com/amazon-eks/1.28.3/2023-11-14/bin/linux/amd64/kubectl curl -O https://s3.us-west-2.amazonaws.com/amazon-eks/1.28.3/2023-11-14/bin/linux/amd64/kubectl.sha256 sha256sum -c kubectl.sha256 chmod +x ./kubectl mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$HOME/bin:$PATH echo 'export PATH=$HOME/bin:$PATH' >> ~/.bashrc kubectl version --client
aws eks --region ap-south-1 update-kubeconfig --name mern-microservice-adarsh
Note if you below error then update awscli version
error-1: Unable to connect to the server: getting credentials: decoding stdout: no kind "ExecCredential" is registered for version "client.authentication.k8s.io/v1alpha1" in scheme
error-2: error: exec plugin: invalid apiVersion “client.authentication.k8s.io/v1alpha1
solution : Update the awscli version
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" sudo apt install unzip unzip awscliv2.zip sudo ./aws/install --update
-
Deploy Application with Helm:
- Use Helm to package and deploy the MERN application on EKS. https://github.com/AdarshIITDH/MERN_Microservices_EKS_Deployment/tree/main/deploy
-
Set Up Monitoring:
- Use CloudWatch for monitoring and setting up alarms.
-
Configure Logging:
- Use CloudWatch Logs or another logging solution for collecting logs.