Skip to content

Commit 0af9146

Browse files
fix: fixed server error
1 parent b407fad commit 0af9146

File tree

3 files changed

+641
-229
lines changed

3 files changed

+641
-229
lines changed

DEPLOYMENT.md

Lines changed: 297 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,300 @@ After deployment, you'll have:
117117
- ✅ Professional presentation of your project
118118
- ✅ Educational value for visitors
119119

120-
**Your federated learning demo will be live and working!** 🚀
120+
**Your federated learning demo will be live and working!** 🚀
121+
122+
# FinFedRAG Deployment Guide
123+
124+
## Overview
125+
126+
This project implements a federated learning framework with RAG capabilities for financial data. The system can be deployed using Docker Compose for local development or Kubernetes for production environments.
127+
128+
## Debugging and Monitoring
129+
130+
### Enhanced Debugging Features
131+
132+
The web application now includes comprehensive debugging capabilities:
133+
134+
1. **Debug Information Panel**: Located in the sidebar, shows:
135+
- Real-time server health status
136+
- Recent debug messages and logs
137+
- Connection error details
138+
- Client simulator status
139+
140+
2. **Detailed Error Logging**: All operations are logged with:
141+
- Connection attempts and failures
142+
- Server response details
143+
- Timeout and network error handling
144+
- Client registration and training status updates
145+
146+
3. **Real-time Status Monitoring**:
147+
- Server health checks
148+
- Training progress tracking
149+
- Client connection status
150+
- Error message history
151+
152+
### Using the Debug Features
153+
154+
1. **Enable Debug Mode**: Uncheck "Demo Mode" in the sidebar
155+
2. **View Debug Information**: Expand the "Debug Information" section in the sidebar
156+
3. **Monitor Logs**: Check the "Recent Logs" section for real-time updates
157+
4. **Clear Logs**: Use the "Clear Debug Logs" button to reset the log history
158+
159+
## Local Development Setup
160+
161+
### Prerequisites
162+
163+
- Python 3.8+
164+
- Docker and Docker Compose
165+
- Required Python packages (see requirements.txt)
166+
167+
### Quick Start
168+
169+
1. **Clone and Setup**:
170+
```bash
171+
git clone <repository-url>
172+
cd FinFedRAG-Financial-Federated-RAG
173+
python -m venv venv
174+
source venv/bin/activate # On Windows: venv\Scripts\activate
175+
pip install -r requirements.txt
176+
```
177+
178+
2. **Start the Federated Server**:
179+
```bash
180+
python src/main.py --mode server
181+
```
182+
183+
3. **Start Multiple Clients** (in separate terminals):
184+
```bash
185+
python src/main.py --mode client --client-id client1
186+
python src/main.py --mode client --client-id client2
187+
python src/main.py --mode client --client-id client3
188+
```
189+
190+
4. **Run the Web Application**:
191+
```bash
192+
streamlit run app.py
193+
```
194+
195+
### Docker Compose Deployment
196+
197+
For containerized deployment:
198+
199+
```bash
200+
cd docker
201+
docker-compose up --build
202+
```
203+
204+
This will start:
205+
- 1 federated server on port 8000
206+
- 3 federated clients
207+
- All services connected via Docker network
208+
209+
## Kubernetes Deployment
210+
211+
### Architecture Overview
212+
213+
The Kubernetes setup provides a production-ready deployment with:
214+
215+
- **Server Deployment**: Single federated learning server
216+
- **Client Deployment**: Multiple federated learning clients (3 replicas)
217+
- **Service Layer**: Internal service discovery
218+
- **ConfigMaps**: Configuration management
219+
- **Namespace Isolation**: Dedicated `federated-learning` namespace
220+
221+
### Components
222+
223+
#### 1. Server Deployment (`kubernetes/deployments/server.yaml`)
224+
```yaml
225+
- Replicas: 1 (single server instance)
226+
- Port: 8000 (internal)
227+
- Config: Mounted from ConfigMap
228+
- Image: fl-server:latest
229+
```
230+
231+
#### 2. Client Deployment (`kubernetes/deployments/client.yaml`)
232+
```yaml
233+
- Replicas: 3 (multiple client instances)
234+
- Environment: SERVER_HOST=fl-server-service
235+
- Config: Mounted from ConfigMap
236+
- Image: fl-client:latest
237+
```
238+
239+
#### 3. Service (`kubernetes/services/service.yaml`)
240+
```yaml
241+
- Type: ClusterIP (internal communication)
242+
- Port: 8000
243+
- Selector: app=fl-server
244+
```
245+
246+
### Deployment Steps
247+
248+
1. **Build Docker Images**:
249+
```bash
250+
docker build -f docker/Dockerfile.server -t fl-server:latest .
251+
docker build -f docker/Dockerfile.client -t fl-client:latest .
252+
```
253+
254+
2. **Create Namespace**:
255+
```bash
256+
kubectl create namespace federated-learning
257+
```
258+
259+
3. **Create ConfigMaps**:
260+
```bash
261+
kubectl create configmap server-config --from-file=config/server_config.yaml -n federated-learning
262+
kubectl create configmap client-config --from-file=config/client_config.yaml -n federated-learning
263+
```
264+
265+
4. **Deploy Services**:
266+
```bash
267+
kubectl apply -f kubernetes/services/service.yaml
268+
kubectl apply -f kubernetes/deployments/server.yaml
269+
kubectl apply -f kubernetes/deployments/client.yaml
270+
```
271+
272+
5. **Verify Deployment**:
273+
```bash
274+
kubectl get pods -n federated-learning
275+
kubectl get services -n federated-learning
276+
```
277+
278+
### Accessing the Application
279+
280+
#### Option 1: Port Forwarding
281+
```bash
282+
kubectl port-forward service/fl-server-service 8080:8000 -n federated-learning
283+
```
284+
285+
#### Option 2: Load Balancer
286+
Modify the service to use LoadBalancer type:
287+
```yaml
288+
apiVersion: v1
289+
kind: Service
290+
metadata:
291+
name: fl-server-service
292+
namespace: federated-learning
293+
spec:
294+
type: LoadBalancer # Changed from ClusterIP
295+
selector:
296+
app: fl-server
297+
ports:
298+
- port: 8080
299+
targetPort: 8000
300+
```
301+
302+
#### Option 3: Ingress Controller
303+
Create an ingress resource for external access:
304+
```yaml
305+
apiVersion: networking.k8s.io/v1
306+
kind: Ingress
307+
metadata:
308+
name: fl-ingress
309+
namespace: federated-learning
310+
spec:
311+
rules:
312+
- host: fl.example.com
313+
http:
314+
paths:
315+
- path: /
316+
pathType: Prefix
317+
backend:
318+
service:
319+
name: fl-server-service
320+
port:
321+
number: 8000
322+
```
323+
324+
### Monitoring and Debugging in Kubernetes
325+
326+
1. **View Pod Logs**:
327+
```bash
328+
kubectl logs -f deployment/fl-server -n federated-learning
329+
kubectl logs -f deployment/fl-client -n federated-learning
330+
```
331+
332+
2. **Check Pod Status**:
333+
```bash
334+
kubectl describe pods -n federated-learning
335+
```
336+
337+
3. **Access Pod Shell**:
338+
```bash
339+
kubectl exec -it <pod-name> -n federated-learning -- /bin/bash
340+
```
341+
342+
4. **Monitor Resource Usage**:
343+
```bash
344+
kubectl top pods -n federated-learning
345+
```
346+
347+
## Troubleshooting
348+
349+
### Common Issues
350+
351+
1. **Connection Refused Errors**:
352+
- Check if server is running: `kubectl get pods -n federated-learning`
353+
- Verify service exists: `kubectl get services -n federated-learning`
354+
- Check pod logs for startup errors
355+
356+
2. **Client Registration Failures**:
357+
- Ensure server is healthy before starting clients
358+
- Check network connectivity between pods
359+
- Verify ConfigMap configurations
360+
361+
3. **Training Status Issues**:
362+
- Monitor server logs for aggregation errors
363+
- Check client participation in training rounds
364+
- Verify model update sharing
365+
366+
### Debug Commands
367+
368+
```bash
369+
# Check all resources in namespace
370+
kubectl get all -n federated-learning
371+
372+
# View detailed pod information
373+
kubectl describe pod <pod-name> -n federated-learning
374+
375+
# Check service endpoints
376+
kubectl get endpoints -n federated-learning
377+
378+
# View ConfigMap contents
379+
kubectl get configmap server-config -n federated-learning -o yaml
380+
```
381+
382+
## Production Considerations
383+
384+
1. **Resource Limits**: Add resource requests and limits to deployments
385+
2. **Health Checks**: Implement liveness and readiness probes
386+
3. **Secrets Management**: Use Kubernetes secrets for sensitive data
387+
4. **Persistent Storage**: Add persistent volumes for model storage
388+
5. **Monitoring**: Integrate with Prometheus/Grafana for metrics
389+
6. **Logging**: Use centralized logging (ELK stack, Fluentd)
390+
391+
## Scaling
392+
393+
### Horizontal Pod Autoscaling
394+
```yaml
395+
apiVersion: autoscaling/v2
396+
kind: HorizontalPodAutoscaler
397+
metadata:
398+
name: fl-client-hpa
399+
namespace: federated-learning
400+
spec:
401+
scaleTargetRef:
402+
apiVersion: apps/v1
403+
kind: Deployment
404+
name: fl-client
405+
minReplicas: 3
406+
maxReplicas: 10
407+
metrics:
408+
- type: Resource
409+
resource:
410+
name: cpu
411+
target:
412+
type: Utilization
413+
averageUtilization: 70
414+
```
415+
416+
This deployment guide provides comprehensive information for both local development and production Kubernetes deployment, with enhanced debugging capabilities for better monitoring and troubleshooting.

0 commit comments

Comments
 (0)