Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
179 changes: 179 additions & 0 deletions k8s/README.md
Original file line number Diff line number Diff line change
@@ -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://<EXTERNAL-IP>`

### 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 <pod-name>
```

### 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/
```
10 changes: 10 additions & 0 deletions k8s/backend-configmap.yaml
Original file line number Diff line number Diff line change
@@ -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"
58 changes: 58 additions & 0 deletions k8s/backend-deployment.yaml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions k8s/frontend-configmap.yaml
Original file line number Diff line number Diff line change
@@ -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"
52 changes: 52 additions & 0 deletions k8s/frontend-deployment.yaml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions k8s/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -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
45 changes: 45 additions & 0 deletions k8s/mongodb-deployment.yaml
Original file line number Diff line number Diff line change
@@ -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