This README provides instructions on how to set up and run the chat application locally. It includes setting up MongoDB, installing the correct version of Node.js, and running the server and client applications.
The application utilizes React for the front end, Express for the back end, and MongoDB as the database.
To install MongoDB on Ubuntu, follow these steps to use the official MongoDB repository:
sudo apt-get install gnupg curl
curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | \
sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org
Install Node.js using NodeSource. This provides the latest versions directly suitable for development:
# Using Ubuntu
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs
Verify the Node.js installation:
node -v
Navigate to both the frontend and backend directories in separate terminal windows and install the necessary packages:
# For backend
cd ./chat-app-backend
npm install
# For frontend
cd ./chat-app-frontend
npm install
Set up the necessary environment variables. Create a .env
file in your backend directory and add the following:
MONGO_URI=mongodb://localhost:27017/chatApp
PORT=3000
Start both the backend and frontend services:
# Start the backend server
cd chat-app/readme.txt
npm start
# In another terminal, start the frontend application
cd ./chat-app-frontend
npm start
Open your web browser and navigate to http://localhost:3000
(or whichever port the frontend is set to use) to view and interact with the chat application.
This section provides a step-by-step guide on how to deploy the chat application using Docker containers and manage it through Kubernetes with Minikube.
Ensure you have the following installed:
- Docker: For creating and managing your application containers.
- Minikube: A tool that allows you to run Kubernetes locally.
- kubectl: A command-line tool for interacting with your Kubernetes cluster.
-
Navigate to the Backend Directory:
- Build the Docker image for the backend.
cd ./chat-app-backend docker build -t chat-app-backend .
-
Modify MongoDB Connection URL:
-
Before deploying MongoDB, modify the MongoDB URL in your backend's environment settings to ensure it connects to the Kubernetes MongoDB service rather than a local instance:
MONGO_URI="mongodb://admin:password@mongodb-service:27017/chatApp?authSource=admin"
-
-
Deploy MongoDB with Docker and Kubernetes:
- MongoDB can be deployed using Docker and managed within Kubernetes independently of the frontend and backend services.
-
Build the MongoDB Docker Image (if using a custom setup):
docker build -t custom-mongo:latest -f Dockerfile.mongo .
-
Deploy MongoDB using Kubernetes:
kubectl apply -f mongodb-deployment.yaml
This will create a MongoDB service and a persistent storage volume to ensure data is not lost when the pod is restarted.
-
Navigate to the Frontend Directory:
- Build the Docker image for the frontend.
cd ./chat-app-frontend docker build -t chat-app-frontend .
- Start your local Kubernetes cluster with Minikube.
minikube start
- This allows you to access your services via an external IP.
minikube addons enable ingress
-
Navigate to the Kubernetes Configuration Directory:
cd ./k8s
-
Apply the Kubernetes Configurations:
- Deploy the backend and frontend services.
kubectl apply -f backend-deployment.yaml kubectl apply -f frontend-deployment.yaml
- Use Minikube to open the frontend service in your default web browser.
minikube service frontend-service
- When you're done, you can stop Minikube and optionally delete all resources.
minikube stop minikube delete
- Configuration Changes: If you update your Docker images, make sure to rebuild them and apply the changes to Kubernetes.