This project demonstrates a microservices architecture using Node.js, deployed on Kubernetes. It consists of three services: User Service, Task Service, and Notification Service, along with MongoDB for data persistence and RabbitMQ for message queuing.
- User Service: Manages user data (CRUD operations)
- Task Service: Handles task management
- Notification Service: Processes notifications via RabbitMQ
- MongoDB: Database for storing user and task data
- RabbitMQ: Message broker for inter-service communication
- Docker installed and running
- Kubernetes cluster (Minikube, Docker Desktop, or cloud provider)
- kubectl configured to access your cluster
- Docker Hub account (for pushing images)
-
Clone this repository:
git clone <repository-url> cd nodejs-microservices-kubernetes
-
Ensure Docker is running and you're logged into Docker Hub:
docker login
Build the Docker images for each service:
# Build images
docker build -t victoriousvipin/nms_user-service ./user-service
docker build -t victoriousvipin/nms_task-service ./task-service
docker build -t victoriousvipin/nms_notification-service ./notification-service
# Push images to Docker Hub
docker push victoriousvipin/nms_user-service:latest
docker push victoriousvipin/nms_task-service:latest
docker push victoriousvipin/nms_notification-service:latestApply the Kubernetes manifests in order:
kubectl apply -f k8s/mongodb-deployment.yml
kubectl apply -f k8s/mongodb-svc.ymlkubectl apply -f k8s/rabbitmq-configmap.yml
kubectl apply -f k8s/rabbitmq-statefulset.yml
kubectl apply -f k8s/rabbitmq-service.ymlkubectl apply -f k8s/user-service-deployment.yml
kubectl apply -f k8s/user-service-svc.yml
kubectl apply -f k8s/task-service-deployment.yml
kubectl apply -f k8s/task-service-svc.yml
kubectl apply -f k8s/notification-service-deployment.yml
kubectl apply -f k8s/notification-service-svc.ymlkubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.10.1/deploy/static/provider/cloud/deploy.yamlkubectl apply -f k8s/ingress.ymlCheck the status of your deployments:
kubectl get podskubectl get svckubectl get deploymentskubectl get ingresskubectl get svc -n ingress-nginxkubectl logs <pod-name>Example:
kubectl logs user-service-abc123-def456kubectl logs deployment/user-servicekubectl describe pod <pod-name>kubectl port-forward svc/user-service 3001:3001Then test the API:
curl http://localhost:3001/api/users-
User Service:
http://localhost/api/users- GET
/api/users- Get all users - POST
/api/users- Create a new user - PUT
/api/users/:id- Update a user - DELETE
/api/users/:id- Delete a user
- GET
-
Task Service:
http://localhost/api/tasks- Similar CRUD operations for tasks
-
Notification Service: Handles notifications via RabbitMQ
Scale deployments as needed:
kubectl scale deployment user-service --replicas=5- Pods not starting: Check pod status with
kubectl describe pod <pod-name> - Services not accessible: Verify service configuration and pod labels
- Ingress not working: Check ingress controller status and ingress rules
- Database connection issues: Ensure MongoDB pod is running and service is accessible
- Image pull errors: Make sure images are pushed to Docker Hub and accessible
To remove all resources:
kubectl delete -f k8s/
kubectl delete -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.10.1/deploy/static/provider/cloud/deploy.yaml