From 5d0cdc9b3cd3621d46f572985c0da6af89adf09b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 20 Nov 2025 13:50:51 +0000 Subject: [PATCH 1/2] Initial plan From d687fa6783b4c5cb3ffab555f51286b975feaff7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 20 Nov 2025 13:55:43 +0000 Subject: [PATCH 2/2] Add Kubernetes deployment manifests with service and configmap Co-authored-by: aditya-nv-06 <138525577+aditya-nv-06@users.noreply.github.com> --- k8s/README.md | 179 +++++++++++++++++++++++++++++++++++ k8s/backend-configmap.yaml | 10 ++ k8s/backend-deployment.yaml | 58 ++++++++++++ k8s/frontend-configmap.yaml | 9 ++ k8s/frontend-deployment.yaml | 52 ++++++++++ k8s/kustomization.yaml | 14 +++ k8s/mongodb-deployment.yaml | 45 +++++++++ 7 files changed, 367 insertions(+) create mode 100644 k8s/README.md create mode 100644 k8s/backend-configmap.yaml create mode 100644 k8s/backend-deployment.yaml create mode 100644 k8s/frontend-configmap.yaml create mode 100644 k8s/frontend-deployment.yaml create mode 100644 k8s/kustomization.yaml create mode 100644 k8s/mongodb-deployment.yaml diff --git a/k8s/README.md b/k8s/README.md new file mode 100644 index 0000000..d33f03d --- /dev/null +++ b/k8s/README.md @@ -0,0 +1,179 @@ +# Kubernetes Deployment for Talent Platform + +This directory contains Kubernetes manifests for deploying the Talent Platform application. + +## Prerequisites + +- Kubernetes cluster (v1.19+) +- kubectl configured to connect to your cluster +- Docker images built for frontend and backend components + +## Building Docker Images + +Before deploying to Kubernetes, build the Docker images: + +```bash +# Build backend image +cd backend +docker build -t backend:latest . + +# Build frontend image +cd frontend +docker build -t frontend:latest . +``` + +## Deployment Order + +Deploy the components in the following order: + +1. **MongoDB** - Database service +2. **Backend ConfigMap** - Configuration for backend application +3. **Backend Deployment & Service** - Backend API service +4. **Frontend ConfigMap** - Configuration for frontend application +5. **Frontend Deployment & Service** - Frontend web application + +## Deploying to Kubernetes + +Apply all manifests: + +```bash +# Deploy MongoDB +kubectl apply -f k8s/mongodb-deployment.yaml + +# Deploy Backend +kubectl apply -f k8s/backend-configmap.yaml +kubectl apply -f k8s/backend-deployment.yaml + +# Deploy Frontend +kubectl apply -f k8s/frontend-configmap.yaml +kubectl apply -f k8s/frontend-deployment.yaml +``` + +Or deploy all at once: + +```bash +kubectl apply -f k8s/ +``` + +## Verifying Deployment + +Check the status of your deployments: + +```bash +# Check all pods +kubectl get pods + +# Check all services +kubectl get services + +# Check deployments +kubectl get deployments + +# Check configmaps +kubectl get configmaps +``` + +## Accessing the Application + +### Frontend + +The frontend service is exposed as a LoadBalancer. Get the external IP: + +```bash +kubectl get service frontend +``` + +Access the application at `http://` + +### Backend API + +The backend service is exposed internally. To access it from outside the cluster for testing: + +```bash +kubectl port-forward service/backend 3001:3001 +``` + +Then access the API at `http://localhost:3001` + +## Architecture + +- **MongoDB**: Single replica database (consider using StatefulSet for production) +- **Backend**: 2 replicas with health checks + - Port 3001: REST API + - Port 8080: WebSocket +- **Frontend**: 2 replicas with health checks + - Port 80: Web application (nginx) + +## Configuration + +### Backend ConfigMap + +Contains environment variables: +- `PORT`: Backend API port (3001) +- `DOCKER_URL`: MongoDB connection string +- `JWT_SECRET`: Secret key for JWT authentication + +### Frontend ConfigMap + +Contains environment variables: +- `VITE_API_URL`: Backend API URL +- `VITE_WS_URL`: Backend WebSocket URL + +## Scaling + +Scale deployments as needed: + +```bash +# Scale backend +kubectl scale deployment backend --replicas=3 + +# Scale frontend +kubectl scale deployment frontend --replicas=3 +``` + +## Troubleshooting + +### Check pod logs + +```bash +# Backend logs +kubectl logs -l app=backend + +# Frontend logs +kubectl logs -l app=frontend + +# MongoDB logs +kubectl logs -l app=mongodb +``` + +### Check pod details + +```bash +kubectl describe pod +``` + +### Common Issues + +1. **ImagePullBackOff**: Ensure Docker images are built and available in your registry +2. **CrashLoopBackOff**: Check pod logs for application errors +3. **Pending Pods**: Check if your cluster has sufficient resources + +## Production Considerations + +For production deployments, consider: + +1. **Persistent Storage**: Use PersistentVolumeClaims for MongoDB data +2. **Secrets Management**: Use Kubernetes Secrets for sensitive data (JWT_SECRET, MongoDB credentials) +3. **Resource Limits**: Define resource requests and limits for containers +4. **Ingress Controller**: Use Ingress instead of LoadBalancer for better routing +5. **Monitoring**: Add monitoring and logging solutions (Prometheus, Grafana, ELK) +6. **High Availability**: Increase replicas and use pod anti-affinity rules +7. **StatefulSet for MongoDB**: For production-grade database deployment + +## Cleanup + +Remove all deployed resources: + +```bash +kubectl delete -f k8s/ +``` diff --git a/k8s/backend-configmap.yaml b/k8s/backend-configmap.yaml new file mode 100644 index 0000000..c9fc62d --- /dev/null +++ b/k8s/backend-configmap.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: backend-config + labels: + app: backend +data: + PORT: "3001" + DOCKER_URL: "mongodb://mongodb:27017/talent_match" + JWT_SECRET: "server" diff --git a/k8s/backend-deployment.yaml b/k8s/backend-deployment.yaml new file mode 100644 index 0000000..0b98429 --- /dev/null +++ b/k8s/backend-deployment.yaml @@ -0,0 +1,58 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: backend + labels: + app: backend +spec: + replicas: 2 + selector: + matchLabels: + app: backend + template: + metadata: + labels: + app: backend + spec: + containers: + - name: backend + image: backend:latest + imagePullPolicy: IfNotPresent + ports: + - containerPort: 3001 + - containerPort: 8080 + envFrom: + - configMapRef: + name: backend-config + livenessProbe: + httpGet: + path: / + port: 3001 + initialDelaySeconds: 30 + periodSeconds: 10 + readinessProbe: + httpGet: + path: / + port: 3001 + initialDelaySeconds: 10 + periodSeconds: 5 +--- +apiVersion: v1 +kind: Service +metadata: + name: backend + labels: + app: backend +spec: + type: ClusterIP + ports: + - name: api + port: 3001 + targetPort: 3001 + protocol: TCP + - name: websocket + port: 8080 + targetPort: 8080 + protocol: TCP + selector: + app: backend diff --git a/k8s/frontend-configmap.yaml b/k8s/frontend-configmap.yaml new file mode 100644 index 0000000..fb313d8 --- /dev/null +++ b/k8s/frontend-configmap.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: frontend-config + labels: + app: frontend +data: + VITE_API_URL: "http://backend:3001" + VITE_WS_URL: "ws://backend:8080" diff --git a/k8s/frontend-deployment.yaml b/k8s/frontend-deployment.yaml new file mode 100644 index 0000000..ec653af --- /dev/null +++ b/k8s/frontend-deployment.yaml @@ -0,0 +1,52 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: frontend + labels: + app: frontend +spec: + replicas: 2 + selector: + matchLabels: + app: frontend + template: + metadata: + labels: + app: frontend + spec: + containers: + - name: frontend + image: frontend:latest + imagePullPolicy: IfNotPresent + ports: + - containerPort: 80 + envFrom: + - configMapRef: + name: frontend-config + livenessProbe: + httpGet: + path: / + port: 80 + initialDelaySeconds: 30 + periodSeconds: 10 + readinessProbe: + httpGet: + path: / + port: 80 + initialDelaySeconds: 10 + periodSeconds: 5 +--- +apiVersion: v1 +kind: Service +metadata: + name: frontend + labels: + app: frontend +spec: + type: LoadBalancer + ports: + - port: 80 + targetPort: 80 + protocol: TCP + selector: + app: frontend diff --git a/k8s/kustomization.yaml b/k8s/kustomization.yaml new file mode 100644 index 0000000..31c8626 --- /dev/null +++ b/k8s/kustomization.yaml @@ -0,0 +1,14 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: + - mongodb-deployment.yaml + - backend-configmap.yaml + - backend-deployment.yaml + - frontend-configmap.yaml + - frontend-deployment.yaml + +commonLabels: + project: talent-platform + +namespace: default diff --git a/k8s/mongodb-deployment.yaml b/k8s/mongodb-deployment.yaml new file mode 100644 index 0000000..ec30474 --- /dev/null +++ b/k8s/mongodb-deployment.yaml @@ -0,0 +1,45 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: mongodb + labels: + app: mongodb +spec: + replicas: 1 + selector: + matchLabels: + app: mongodb + template: + metadata: + labels: + app: mongodb + spec: + containers: + - name: mongodb + image: mongo:latest + ports: + - containerPort: 27017 + env: + - name: MONGO_INITDB_DATABASE + value: "talent_match" + volumeMounts: + - name: mongodb-storage + mountPath: /data/db + volumes: + - name: mongodb-storage + emptyDir: {} +--- +apiVersion: v1 +kind: Service +metadata: + name: mongodb + labels: + app: mongodb +spec: + type: ClusterIP + ports: + - port: 27017 + targetPort: 27017 + protocol: TCP + selector: + app: mongodb