Deploying the Application to Kubernetes
This guide outlines the steps to deploy the application on Kubernetes, using the provided YAML manifests. The setup supports both standard Kubernetes clusters and Minikube for local testing.
Prerequisites
- Kubernetes Cluster
- A working Kubernetes cluster (e.g., Minikube, Docker Desktop, or a cloud provider).
- kubectl CLI
- Ensure
kubectl
is installed and configured to interact with your cluster.
- Ensure
- Docker Hub Access
- All Docker images are publicly available on Docker Hub. Ensure you have internet access to pull these images.
Deploying to Kubernetes
1. Clone the Repository
git clone https://github.com/Sidd-77/microservices-chat.git
cd microservices-chat
2. Configure Secrets
- Create Kubernetes Secrets: Copy the example secrets file:
cp k8s/secrets.example.yml k8s/secrets.yml
- Edit
secrets.yml
: Replace placeholders with appropriate values, such as database credentials, API keys, and S3 access keys. - Apply Secrets:
kubectl apply -f k8s/secrets.yml
3. Install NGINX Ingress Controller
- For routing traffic, install the NGINX ingress controller:
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/cloud/deploy.yaml
- Verify the ingress controller is running:
kubectl get pods -n ingress-nginx
4. Deploy Dependencies
Each dependency has its own deployment and service YAML file. Deploy them as follows:
- Deploy RabbitMQ:
kubectl apply -f k8s/rabbitmq.yml
- Deploy Redis:
kubectl apply -f k8s/redis.yml
- Deploy MinIO:
kubectl apply -f k8s/minio.yml
- Deploy MongoDB:
kubectl apply -f k8s/mongo.yml
5. Deploy Services
Each microservice also has its own deployment and service YAML file. Deploy them as follows:
- Auth Service:
kubectl apply -f k8s/auth-service.yml
- DB Service:
kubectl apply -f k8s/db-service.yml
- File Service:
kubectl apply -f k8s/file-service.yml
- Notification Service:
kubectl apply -f k8s/notification-service.yml
- Socket Service:
kubectl apply -f k8s/socket-service.yml
- Web Frontend:
kubectl apply -f k8s/web.yml
6. Configure Ingress
- Apply the ingress configuration to route traffic:
kubectl apply -f k8s/ingress.yml
- Verify ingress is working:
Ensure external IPs or hostnames are assigned.kubectl get ingress
7. Verify Deployment
- Check pods' status:
kubectl get pods
- Access logs for debugging:
kubectl logs <pod-name>
- Test the application by accessing the exposed endpoints.
Running in Minikube
Additional Steps for Minikube
- Start Minikube:
minikube start
- Enable Ingress Controller:
minikube addons enable ingress
- Install NGINX Ingress Controller:
Use the following command to ensure ingress works locally:
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/cloud/deploy.yaml
- Expose Services:
Since Minikube runs locally, expose services for testing:
minikube service <service-name>
- Access Application:
Use
minikube tunnel
to expose the services:
This command will create a network route to access the services using their cluster IPs and ports.minikube tunnel
Tips for Minikube
- Use the
--memory
and--cpus
flags to allocate sufficient resources:minikube start --memory=4g --cpus=2
- Use the Minikube dashboard to monitor resources:
minikube dashboard