This project demonstrates how to deploy a 3-tier application (React frontend, Node.js backend, and MongoDB database) to a Kubernetes cluster using Docker images and Helm.
- Docker installed on your local machine
- Kubernetes cluster (local or cloud-based)
- Helm package manager installed on your local machine
The 3-tier application consists of the following components:
- Frontend: A React application serving the user interface.
- Backend: A Node.js application that handles the business logic and interacts with the database.
- MongoDB: A NoSQL database for storing application data.
- Navigate to the
frontend
directory and build the Docker image for the React application:cd frontend docker build -t your-docker-username/frontend:1.0.0 .
- Navigate to the
backend
directory and build the Docker image for the Node.js application:cd ../backend docker build -t your-docker-username/backend:1.0.0 .
- Push the Docker images to a container registry (e.g., Docker Hub, ECR, GCR):
docker push your-docker-username/frontend:1.0.0 docker push your-docker-username/backend:1.0.0
- Navigate to the
3-tier-app
directory:cd 3-tier-app
- Update the
values.yaml
file with the appropriate Docker image tags and any other configuration settings. - Install the Helm chart:
helm install 3-tier-app .
- This will deploy the 3-tier application to your Kubernetes cluster, including the following resources:
- Namespace (3-tier)
- MongoDB StatefulSet
- Secrets for Mongo Auth
- PersistentVolume to attach to Mongo database
- Backend Deployment
- Frontend Deployment
- MongoDB Service
- Backend Service
- Frontend Service
- Ingress (optional)
- After the deployment is complete, you can access the frontend application using the provided ingress or load balancer URL.
- Alternatively, you can use
kubectl port-forward
to access the frontend service locally:Then, openkubectl port-forward service/frontend 8080:80
http://localhost:8080
in your web browser.
You can customize the deployment by modifying the following files:
helm/values.yaml
: Update environment variables, resource requests/limits, and other configurations.helm/templates/
: Modify the Kubernetes manifests for each component (Deployments, Services, Ingress, etc.).
To remove the 3-tier application from your Kubernetes cluster, run the following command:
helm uninstall 3-tier-app
This will delete all the resources associated with the application.
If you're using Minikube, follow these additional steps:
-
Start Minikube:
minikube start
-
Build Docker Images: Skip this step if you've already built and pushed the Docker images.
-
Deploy with Helm: Follow the instructions in the "Deploy with Helm" section above.
-
Access the Application: Follow the instructions in the "Access the Application" section above.
After cleaning up, you can stop the Minikube cluster by running:
minikube stop