Skip to content

thunderbirdgit/hw-nodejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hello-World UI Service: Retrieve Data from MongoDB Using Node.js

Project Description

Overview

The Hello World UI service project is designed to deploy a Node.js web application using an Amazon EKS Cluster. The project utilizes Docker for containerization and Amazon Elastic Container Registry (ECR) for storing Docker images. It integrates with Kubernetes for application deployment.

Goals

  • Deploy Node.js Application: Containerize and deploy a Node.js web application to an EKS cluster.
  • Manage Docker Images: Use an ECR repository to store and manage Docker images.
  • Create MongoDB Instance in EKS: Set up a MongoDB replica set in the EKS Cluster.
  • Access Data from MongoDB: Retrieve data from MongoDB and display it in the Node.js application.
  • Access Node.js Application from Load Balancer: Access the Node.js application through the Load Balancer endpoint.
  • GitOps Workflow for Node.js application: Setup GitOps workflow to build, tag and publish container images to ECR repository for node.js application

Architecture Diagram

Architecture Diagram

Setup Instructions

1. Clone the Repository

Clone the repository to your local machine:

git clone https://github.com/thunderbirdgit/hw-nodejs.git

2. GitOps Workflow

  1. Create a feature branch and make the required changes to the application repository.

  2. Store AWS Credentials such as Access key, Region, Account ID and Secret keys in secrets and variables in Github repository settings

    image
  3. GitHub Actions will be executed as part of the pre-commit check workflow.

    image
  4. Once the PR checks are green, the user will be allowed to merge the pull request. Merging will be blocked unless the checks are green.

  5. Once the changes are merged, the GitOps workflow will clone, build, tag, and publish the Docker image to the ECR repository.

    image
  6. You can verify that the Docker image is pushed to the ECR repository.

    image

3. Kubernetes Manifests:

  1. The manifests/ folder in the repository contains the following deployment files to deploy the Node.js application, create Kubernetes services and Ingress layers, and create MongoDB instances.

  2. Node.js Application Setup:

  • deployment.yml: Creates the hw-nodejs DeploymentSet with the number of replicas, pulls the image from the Docker container, and exposes port 3000 for service access.
  • service.yml: Creates a Kubernetes service layer to access the application on port 3000.
  • ingress.yml: Sets up an Ingress layer using NGINX as the reverse proxy, allowing the Node.js application to be accessed through dev.helloworld.com. NGINX acts as a load balancer to route application traffic through the ALB.
  1. MongoDB Setup:
  • mongodb.yml: Creates a MongoDB cluster as a StatefulSet, specifying the number of replicas, required mountPath, and volumeMounts.
  • mongodb-service.yml: Creates a MongoDB Kubernetes service layer.
  • mongodb-loadbalancer.yml: Creates a dev-mongodb-lb load balancer layer.

4. Mongo DB Data setup:

  1. Create the helloworld database in MongoDB.
  2. Create the messages collection.
  3. Insert "Hello World!!" data into the messages collection:
    mongosh "mongodb://<mongodb_hostname>:27017"
    > use helloworld;
    > db.messages.insertOne({ message: "Hello World !!" });
    > db.messages.find().pretty();
    
    image

5. Deploy NGINX controller:

Deploy the NGINX Kubernetes controller:

$ helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
$ helm upgrade -i ingress-nginx ingress-nginx/ingress-nginx --version 4.2.3 --namespace kube-system --set controller.service.type=ClusterIP

$ kubectl -n kube-system rollout status deployment ingress-nginx-controller
deployment "ingress-nginx-controller" successfully rolled out

$ kubectl get deployment -n kube-system ingress-nginx-controller
NAME                       READY   UP-TO-DATE   AVAILABLE   AGE
ingress-nginx-controller   1/1     1            1           44h

$ kubectl get pods -n kube-system | grep nginx
ingress-nginx-controller-7f49ccf564-mnfmk   1/1     Running   0          44h

6. Apply Kubernetes changes

Apply the Kubernetes changes:

cd hw-nodejs/manifests
kubectl apply -f .

7. Access the Application

In a real-world scenario, dev.helloworld.com will be registered through domain registration providers. For the purposes of this exercise, modify the /etc/hosts file on your laptop or other device to access http://dev.helloworld.com through the Ingress IP.

image image

8. Monitor Ingress Logs

Ingress access logs can be accessed by running: kubectl logs <nginx_controller_pod> -n kube-system
image

9. Cleanup

To clean up resources, run:

kubectl delete deployment hw-nodejs;
kubectl delete service hw-nodejs;
kubectl delete ingress hw-nodejs

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published