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.
- 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
Clone the repository to your local machine:
git clone https://github.com/thunderbirdgit/hw-nodejs.git
-
Create a feature branch and make the required changes to the application repository.
-
Store AWS Credentials such as Access key, Region, Account ID and Secret keys in secrets and variables in Github repository settings
-
GitHub Actions will be executed as part of the pre-commit check workflow.
-
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.
-
Once the changes are merged, the GitOps workflow will clone, build, tag, and publish the Docker image to the ECR repository.
-
You can verify that the Docker image is pushed to the ECR repository.
-
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.
-
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.
- 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.
- Create the helloworld database in MongoDB.
- Create the messages collection.
- 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();
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
Apply the Kubernetes changes:
cd hw-nodejs/manifests
kubectl apply -f .
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.
Ingress access logs can be accessed by running: kubectl logs <nginx_controller_pod> -n kube-system
To clean up resources, run:
kubectl delete deployment hw-nodejs;
kubectl delete service hw-nodejs;
kubectl delete ingress hw-nodejs