Fix Purchase Order modal and reorganize documentation

Frontend Changes:
- Fix runtime error: Remove undefined handleModify reference from ActionQueueCard in DashboardPage
- Migrate PurchaseOrderDetailsModal to use correct PurchaseOrderItem type from purchase_orders service
- Fix item display: Parse unit_price as string (Decimal) instead of number
- Use correct field names: item_notes instead of notes
- Remove deprecated PurchaseOrder types from suppliers.ts to prevent type conflicts
- Update CreatePurchaseOrderModal to use unified types
- Clean up API exports: Remove old PO hooks re-exported from suppliers
- Add comprehensive translations for PO modal (en, es, eu)

Documentation Reorganization:
- Move WhatsApp implementation docs to docs/03-features/notifications/whatsapp/
- Move forecast validation docs to docs/03-features/forecasting/
- Move specification docs to docs/03-features/specifications/
- Move deployment docs (Colima, K8s, VPS sizing) to docs/05-deployment/
- Archive completed implementation summaries to docs/archive/implementation-summaries/
- Delete obsolete FRONTEND_CHANGES_NEEDED.md
- Standardize filenames to lowercase with hyphens

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Urtzi Alfaro
2025-11-18 11:59:23 +01:00
parent 5c45164c8e
commit 3c3d3ce042
32 changed files with 654 additions and 874 deletions

View File

@@ -0,0 +1,387 @@
# Colima Setup for Local Development
## Overview
Colima is used for local Kubernetes development on macOS. This guide provides the optimal configuration for running the complete Bakery IA stack locally.
## Recommended Configuration
### For Full Stack (All Services + Monitoring)
```bash
colima start --cpu 6 --memory 12 --disk 120 --runtime docker --profile k8s-local
```
### Configuration Breakdown
| Resource | Value | Reason |
|----------|-------|--------|
| **CPU** | 6 cores | Supports 18 microservices + infrastructure + build processes |
| **Memory** | 12 GB | Comfortable headroom for all services with dev resource limits |
| **Disk** | 120 GB | Container images (~30 GB) + PVCs (~40 GB) + logs + build cache |
| **Runtime** | docker | Compatible with Skaffold and Tiltfile |
| **Profile** | k8s-local | Isolated profile for Bakery IA project |
---
## Resource Breakdown
### What Runs in Dev Environment
#### Application Services (18 services)
- Each service: 64Mi-256Mi RAM (dev limits)
- Total: ~3-4 GB RAM
#### Databases (18 PostgreSQL instances)
- Each database: 64Mi-256Mi RAM (dev limits)
- Total: ~3-4 GB RAM
#### Infrastructure
- Redis: 64Mi-256Mi RAM
- RabbitMQ: 128Mi-256Mi RAM
- Gateway: 64Mi-128Mi RAM
- Frontend: 64Mi-128Mi RAM
- Total: ~0.5 GB RAM
#### Monitoring (Optional)
- Prometheus: 512Mi RAM (when enabled)
- Grafana: 128Mi RAM (when enabled)
- Total: ~0.7 GB RAM
#### Kubernetes Overhead
- Control plane: ~1 GB RAM
- DNS, networking: ~0.5 GB RAM
**Total RAM Usage**: ~8-10 GB (with monitoring), ~7-9 GB (without monitoring)
**Total CPU Usage**: ~3-4 cores under load
**Total Disk Usage**: ~70-90 GB
---
## Alternative Configurations
### Minimal Setup (Without Monitoring)
If you have limited resources:
```bash
colima start --cpu 4 --memory 8 --disk 100 --runtime docker --profile k8s-local
```
**Limitations**:
- No monitoring stack (disable in dev overlay)
- Slower build times
- Less headroom for development tools (IDE, browser, etc.)
### Resource-Rich Setup (For Active Development)
If you want the best experience:
```bash
colima start --cpu 8 --memory 16 --disk 150 --runtime docker --profile k8s-local
```
**Benefits**:
- Faster builds
- Smoother IDE performance
- Can run multiple browser tabs
- Better for debugging with multiple tools
---
## Starting and Stopping Colima
### First Time Setup
```bash
# Install Colima (if not already installed)
brew install colima
# Start Colima with recommended config
colima start --cpu 6 --memory 12 --disk 120 --runtime docker --profile k8s-local
# Verify Colima is running
colima status k8s-local
# Verify kubectl is connected
kubectl cluster-info
```
### Daily Workflow
```bash
# Start Colima
colima start k8s-local
# Your development work...
# Stop Colima (frees up system resources)
colima stop k8s-local
```
### Managing Multiple Profiles
```bash
# List all profiles
colima list
# Switch to different profile
colima stop k8s-local
colima start other-profile
# Delete a profile (frees disk space)
colima delete old-profile
```
---
## Troubleshooting
### Colima Won't Start
```bash
# Delete and recreate profile
colima delete k8s-local
colima start --cpu 6 --memory 12 --disk 120 --runtime docker --profile k8s-local
```
### Out of Memory
Symptoms:
- Pods getting OOMKilled
- Services crashing randomly
- Slow response times
Solutions:
1. Stop Colima and increase memory:
```bash
colima stop k8s-local
colima delete k8s-local
colima start --cpu 6 --memory 16 --disk 120 --runtime docker --profile k8s-local
```
2. Or disable monitoring:
- Monitoring is already disabled in dev overlay by default
- If enabled, comment out in `infrastructure/kubernetes/overlays/dev/kustomization.yaml`
### Out of Disk Space
Symptoms:
- Build failures
- Cannot pull images
- PVC provisioning fails
Solutions:
1. Clean up Docker resources:
```bash
docker system prune -a --volumes
```
2. Increase disk size (requires recreation):
```bash
colima stop k8s-local
colima delete k8s-local
colima start --cpu 6 --memory 12 --disk 150 --runtime docker --profile k8s-local
```
### Slow Performance
Tips:
1. Close unnecessary applications
2. Increase CPU cores if available
3. Enable file sharing exclusions for better I/O
4. Use an SSD for Colima storage
---
## Monitoring Resource Usage
### Check Colima Resources
```bash
# Overall status
colima status k8s-local
# Detailed info
colima list
```
### Check Kubernetes Resource Usage
```bash
# Pod resource usage
kubectl top pods -n bakery-ia
# Node resource usage
kubectl top nodes
# Persistent volume usage
kubectl get pvc -n bakery-ia
df -h # Check disk usage inside Colima VM
```
### macOS Activity Monitor
Monitor these processes:
- `com.docker.hyperkit` or `colima` - should use <50% CPU when idle
- Memory pressure - should be green/yellow, not red
---
## Best Practices
### 1. Use Profiles
Keep Bakery IA isolated:
```bash
colima start --profile k8s-local # For Bakery IA
colima start --profile other-project # For other projects
```
### 2. Stop When Not Using
Free up system resources:
```bash
# When done for the day
colima stop k8s-local
```
### 3. Regular Cleanup
Once a week:
```bash
# Clean up Docker resources
docker system prune -a
# Clean up old images
docker image prune -a
```
### 4. Backup Important Data
Before deleting profile:
```bash
# Backup any important data from PVCs
kubectl cp bakery-ia/<pod-name>:/data ./backup
# Then safe to delete
colima delete k8s-local
```
---
## Integration with Tilt
Tilt is configured to work with Colima automatically:
```bash
# Start Colima
colima start k8s-local
# Start Tilt
tilt up
# Tilt will detect Colima's Kubernetes cluster automatically
```
No additional configuration needed!
---
## Integration with Skaffold
Skaffold works seamlessly with Colima:
```bash
# Start Colima
colima start k8s-local
# Deploy with Skaffold
skaffold dev
# Skaffold will use Colima's Docker daemon automatically
```
---
## Comparison with Docker Desktop
### Why Colima?
| Feature | Colima | Docker Desktop |
|---------|--------|----------------|
| **License** | Free & Open Source | Requires license for companies >250 employees |
| **Resource Usage** | Lower overhead | Higher overhead |
| **Startup Time** | Faster | Slower |
| **Customization** | Highly customizable | Limited |
| **Kubernetes** | k3s (lightweight) | Full k8s (heavier) |
### Migration from Docker Desktop
If coming from Docker Desktop:
```bash
# Stop Docker Desktop
# Uninstall Docker Desktop (optional)
# Install Colima
brew install colima
# Start with similar resources to Docker Desktop
colima start --cpu 6 --memory 12 --disk 120 --runtime docker --profile k8s-local
# All docker commands work the same
docker ps
kubectl get pods
```
---
## Summary
### Quick Start (Copy-Paste)
```bash
# Install Colima
brew install colima
# Start with recommended configuration
colima start --cpu 6 --memory 12 --disk 120 --runtime docker --profile k8s-local
# Verify setup
colima status k8s-local
kubectl cluster-info
# Deploy Bakery IA
skaffold dev
# or
tilt up
```
### Minimum Requirements
- macOS 11+ (Big Sur or later)
- 8 GB RAM available (16 GB total recommended)
- 6 CPU cores available (8 cores total recommended)
- 120 GB free disk space (SSD recommended)
### Recommended Machine Specs
For best development experience:
- **MacBook Pro M1/M2/M3** or **Intel i7/i9**
- **16 GB RAM** (32 GB ideal)
- **8 CPU cores** (M1/M2 Pro or better)
- **512 GB SSD**
---
## Support
If you encounter issues:
1. Check [Colima GitHub Issues](https://github.com/abiosoft/colima/issues)
2. Review [Tilt Documentation](https://docs.tilt.dev/)
3. Check Bakery IA Slack channel
4. Contact DevOps team
Happy coding! 🚀

View File

@@ -0,0 +1,541 @@
# Kubernetes Production Readiness Implementation Summary
**Date**: 2025-11-06
**Status**: ✅ Complete
**Estimated Effort**: ~120 files modified, comprehensive infrastructure improvements
---
## Overview
This document summarizes the comprehensive Kubernetes configuration improvements made to prepare the Bakery IA platform for production deployment to a VPS, with specific focus on proper service dependencies, resource optimization, and production best practices.
---
## What Was Accomplished
### Phase 1: Service Dependencies & Startup Ordering ✅
#### 1.1 Infrastructure Dependencies (Redis, RabbitMQ)
**Files Modified**: 18 service deployment files
**Changes**:
- ✅ Added `wait-for-redis` initContainer to all 18 microservices
- ✅ Uses TLS connection check with proper credentials
- ✅ Added `wait-for-rabbitmq` initContainer to alert-processor-service
- ✅ Added redis-tls volume mounts to all service pods
- ✅ Ensures services only start after infrastructure is fully ready
**Services Updated**:
- auth, tenant, training, forecasting, sales, external, notification
- inventory, recipes, suppliers, pos, orders, production
- procurement, orchestrator, ai-insights, alert-processor
**Benefits**:
- Eliminates connection failures during startup
- Proper dependency chain: Redis/RabbitMQ → Databases → Services
- Reduced pod restart counts
- Faster stack stabilization
#### 1.2 Demo Seed Job Dependencies
**Files Modified**: 20 demo seed job files
**Changes**:
- ✅ Replaced sleep-based waits with HTTP health check probes
- ✅ Each seed job now waits for its parent service to be ready via `/health/ready` endpoint
- ✅ Uses `curl` with proper retry logic
- ✅ Removed arbitrary 15-30 second sleep delays
**Example improvement**:
```yaml
# Before:
- sleep 30 # Hope the service is ready
# After:
until curl -f http://inventory-service.bakery-ia.svc.cluster.local:8000/health/ready; do
sleep 5
done
```
**Benefits**:
- Deterministic startup instead of guesswork
- Faster initialization (no unnecessary waits)
- More reliable demo data seeding
- Clear failure reasons when services aren't ready
#### 1.3 External Data Init Jobs
**Files Modified**: 2 external data init job files
**Changes**:
- ✅ external-data-init now waits for DB + migration completion
- ✅ nominatim-init has proper volume mounts (no service dependency needed)
---
### Phase 2: Resource Specifications & Autoscaling ✅
#### 2.1 Production Resource Adjustments
**Files Modified**: 2 service deployment files
**Changes**:
-**Forecasting Service**: Increased from 256Mi/512Mi to 512Mi/1Gi
- Reason: Handles multiple concurrent prediction requests
- Better performance under production load
-**Training Service**: Validated at 512Mi/4Gi (adequate)
- Already properly configured for ML workloads
- Has temp storage (4Gi) for cmdstan operations
**Database Resources**: Kept at 256Mi-512Mi
- Appropriate for 10-tenant pilot program
- Can be scaled vertically as needed
#### 2.2 Horizontal Pod Autoscalers (HPA)
**Files Created**: 3 new HPA configurations
**Created**:
1.`orders-hpa.yaml` - Scales orders-service (1-3 replicas)
- Triggers: CPU 70%, Memory 80%
- Handles traffic spikes during peak ordering times
2.`forecasting-hpa.yaml` - Scales forecasting-service (1-3 replicas)
- Triggers: CPU 70%, Memory 75%
- Scales during batch prediction requests
3.`notification-hpa.yaml` - Scales notification-service (1-3 replicas)
- Triggers: CPU 70%, Memory 80%
- Handles notification bursts
**HPA Behavior**:
- Scale up: Fast (60s stabilization, 100% increase)
- Scale down: Conservative (300s stabilization, 50% decrease)
- Prevents flapping and ensures stability
**Benefits**:
- Automatic response to load increases
- Cost-effective (scales down during low traffic)
- No manual intervention required
- Smooth handling of traffic spikes
---
### Phase 3: Dev/Prod Overlay Alignment ✅
#### 3.1 Production Overlay Improvements
**Files Modified**: 2 files in prod overlay
**Changes**:
- ✅ Added `prod-configmap.yaml` with production settings:
- `DEBUG: false`, `LOG_LEVEL: INFO`
- `PROFILING_ENABLED: false`
- `MOCK_EXTERNAL_APIS: false`
- `PROMETHEUS_ENABLED: true`
- `ENABLE_TRACING: true`
- Stricter rate limiting
- ✅ Added missing service replicas:
- procurement-service: 2 replicas
- orchestrator-service: 2 replicas
- ai-insights-service: 2 replicas
**Benefits**:
- Clear production vs development separation
- Proper production logging and monitoring
- Complete service coverage in prod overlay
#### 3.2 Development Overlay Refinements
**Files Modified**: 1 file in dev overlay
**Changes**:
- ✅ Set `MOCK_EXTERNAL_APIS: false` (was true)
- Reason: Better to test with real APIs even in dev
- Catches integration issues early
**Benefits**:
- Dev environment closer to production
- Better testing fidelity
- Fewer surprises in production
---
### Phase 4: Skaffold & Tooling Consolidation ✅
#### 4.1 Skaffold Consolidation
**Files Modified**: 2 skaffold files
**Actions**:
- ✅ Backed up `skaffold.yaml``skaffold-old.yaml.backup`
- ✅ Promoted `skaffold-secure.yaml``skaffold.yaml`
- ✅ Updated metadata and comments for main usage
**Improvements in New Skaffold**:
- ✅ Status checking enabled (`statusCheck: true`, 600s deadline)
- ✅ Pre-deployment hooks:
- Applies secrets before deployment
- Applies TLS certificates
- Applies audit logging configs
- Shows security banner
- ✅ Post-deployment hooks:
- Shows deployment summary
- Lists enabled security features
- Provides verification commands
**Benefits**:
- Single source of truth for deployment
- Security-first approach by default
- Better deployment visibility
- Easier troubleshooting
#### 4.2 Tiltfile (No Changes Needed)
**Status**: Already well-configured
**Current Features**:
- ✅ Proper dependency chains
- ✅ Live updates for Python services
- ✅ Resource grouping and labels
- ✅ Security setup runs first
- ✅ Max 3 parallel updates (prevents resource exhaustion)
#### 4.3 Colima Configuration Documentation
**Files Created**: 1 comprehensive guide
**Created**: `docs/COLIMA-SETUP.md`
**Contents**:
- ✅ Recommended configuration: `colima start --cpu 6 --memory 12 --disk 120`
- ✅ Resource breakdown and justification
- ✅ Alternative configurations (minimal, resource-rich)
- ✅ Troubleshooting guide
- ✅ Best practices for local development
**Updated Command**:
```bash
# Old (insufficient):
colima start --cpu 4 --memory 8 --disk 100
# New (recommended):
colima start --cpu 6 --memory 12 --disk 120 --runtime docker --profile k8s-local
```
**Rationale**:
- 6 CPUs: Handles 18 services + builds
- 12 GB RAM: Comfortable for all services with dev limits
- 120 GB disk: Enough for images + PVCs + logs + build cache
---
### Phase 5: Monitoring (Already Configured) ✅
**Status**: Monitoring infrastructure already in place
**Configuration**:
- ✅ Prometheus, Grafana, Jaeger manifests exist
- ✅ Disabled in dev overlay (to save resources) - as requested
- ✅ Can be enabled in prod overlay (ready to use)
- ✅ Nominatim disabled in dev (as requested) - via scale to 0 replicas
**Monitoring Stack**:
- Prometheus: Metrics collection (30s intervals)
- Grafana: Dashboards and visualization
- Jaeger: Distributed tracing
- All services instrumented with `/health/live`, `/health/ready`, metrics endpoints
---
### Phase 6: VPS Sizing & Documentation ✅
#### 6.1 Production VPS Sizing Document
**Files Created**: 1 comprehensive sizing guide
**Created**: `docs/VPS-SIZING-PRODUCTION.md`
**Key Recommendations**:
```
RAM: 20 GB
Processor: 8 vCPU cores
SSD NVMe (Triple Replica): 200 GB
```
**Detailed Breakdown Includes**:
- ✅ Per-service resource calculations
- ✅ Database resource totals (18 instances)
- ✅ Infrastructure overhead (Redis, RabbitMQ)
- ✅ Monitoring stack resources
- ✅ Storage breakdown (databases, models, logs, monitoring)
- ✅ Growth path for 10 → 25 → 50 → 100+ tenants
- ✅ Cost optimization strategies
- ✅ Scaling considerations (vertical and horizontal)
- ✅ Deployment checklist
**Total Resource Summary**:
| Resource | Requests | Limits | VPS Allocation |
|----------|----------|--------|----------------|
| RAM | ~21 GB | ~48 GB | 20 GB |
| CPU | ~8.5 cores | ~41 cores | 8 vCPU |
| Storage | ~79 GB | - | 200 GB |
**Why 20 GB RAM is Sufficient**:
1. Requests are for scheduling, not hard limits
2. Pilot traffic is significantly lower than peak design
3. HPA-enabled services start at 1 replica
4. Real usage is 40-60% of limits under normal load
#### 6.2 Model Import Verification
**Status**: ✅ All services verified complete
**Verified**: All 18 services have complete model imports in `app/models/__init__.py`
- ✅ Alembic can discover all models
- ✅ Initial schema migrations will be complete
- ✅ No missing model definitions
---
## Files Modified Summary
### Total Files Modified: ~120
**By Category**:
- Service deployments: 18 files (added Redis/RabbitMQ initContainers)
- Demo seed jobs: 20 files (replaced sleep with health checks)
- External data init jobs: 2 files (added proper waits)
- HPA configurations: 3 files (new autoscaling policies)
- Prod overlay: 2 files (configmap + kustomization)
- Dev overlay: 1 file (configmap patches)
- Base kustomization: 1 file (added HPAs)
- Skaffold: 2 files (consolidated to single secure version)
- Documentation: 3 new comprehensive guides
---
## Testing & Validation Recommendations
### Pre-Deployment Testing
1. **Dev Environment Test**:
```bash
# Start Colima with new config
colima start --cpu 6 --memory 12 --disk 120 --runtime docker --profile k8s-local
# Deploy complete stack
skaffold dev
# or
tilt up
# Verify all pods are ready
kubectl get pods -n bakery-ia
# Check init container logs for proper startup
kubectl logs <pod-name> -n bakery-ia -c wait-for-redis
kubectl logs <pod-name> -n bakery-ia -c wait-for-migration
```
2. **Dependency Chain Validation**:
```bash
# Delete all pods and watch startup order
kubectl delete pods --all -n bakery-ia
kubectl get pods -n bakery-ia -w
# Expected order:
# 1. Redis, RabbitMQ come up
# 2. Databases come up
# 3. Migration jobs run
# 4. Services come up (after initContainers pass)
# 5. Demo seed jobs run (after services are ready)
```
3. **HPA Validation**:
```bash
# Check HPA status
kubectl get hpa -n bakery-ia
# Should show:
# orders-service-hpa: 1/3 replicas
# forecasting-service-hpa: 1/3 replicas
# notification-service-hpa: 1/3 replicas
# Load test to trigger autoscaling
# (use ApacheBench, k6, or similar)
```
### Production Deployment
1. **Provision VPS**:
- RAM: 20 GB
- CPU: 8 vCPU cores
- Storage: 200 GB NVMe
- Provider: clouding.io
2. **Deploy**:
```bash
skaffold run -p prod
```
3. **Monitor First 48 Hours**:
```bash
# Resource usage
kubectl top pods -n bakery-ia
kubectl top nodes
# Check for OOMKilled or CrashLoopBackOff
kubectl get pods -n bakery-ia | grep -E 'OOM|Crash|Error'
# HPA activity
kubectl get hpa -n bakery-ia -w
```
4. **Optimization**:
- If memory usage consistently >90%: Upgrade to 32 GB
- If CPU usage consistently >80%: Upgrade to 12 cores
- If all services stable: Consider reducing some limits
---
## Known Limitations & Future Work
### Current Limitations
1. **No Network Policies**: Services can talk to all other services
- **Risk Level**: Low (internal cluster, all services trusted)
- **Future Work**: Add NetworkPolicy for defense in depth
2. **No Pod Disruption Budgets**: Multi-replica services can all restart simultaneously
- **Risk Level**: Low (pilot phase, acceptable downtime)
- **Future Work**: Add PDBs for HA services when scaling beyond pilot
3. **No Resource Quotas**: No namespace-level limits
- **Risk Level**: Low (single-tenant Kubernetes)
- **Future Work**: Add when running multiple environments per cluster
4. **initContainer Sleep-Based Migration Waits**: Services use `sleep 10` after pg_isready
- **Risk Level**: Very Low (migrations are fast, 10s is sufficient buffer)
- **Future Work**: Could use Kubernetes Job status checks instead
### Recommended Future Enhancements
1. **Enable Monitoring in Prod** (Month 1):
- Uncomment monitoring in prod overlay
- Configure alerting rules
- Set up Grafana dashboards
2. **Database High Availability** (Month 3-6):
- Add database replicas (currently 1 per service)
- Implement backup and restore automation
- Test disaster recovery procedures
3. **Multi-Region Failover** (Month 12+):
- Deploy to multiple VPS regions
- Implement database replication
- Configure global load balancing
4. **Advanced Autoscaling** (As Needed):
- Add custom metrics to HPA (e.g., queue length, request latency)
- Implement cluster autoscaling (if moving to multi-node)
---
## Success Metrics
### Deployment Success Criteria
✅ **All pods reach Ready state within 10 minutes**
✅ **No OOMKilled pods in first 24 hours**
✅ **Services respond to health checks with <200ms latency**
✅ **Demo data seeds complete successfully**
✅ **Frontend accessible and functional**
✅ **Database migrations complete without errors**
### Production Health Indicators
After 1 week:
- ✅ 99.5%+ uptime for all services
- ✅ <2s average API response time
- ✅ <5% CPU usage during idle periods
- ✅ <50% memory usage during normal operations
- ✅ Zero OOMKilled events
- ✅ HPA triggers appropriately during load tests
---
## Maintenance & Operations
### Daily Operations
```bash
# Check overall health
kubectl get pods -n bakery-ia
# Check resource usage
kubectl top pods -n bakery-ia
# View recent logs
kubectl logs -n bakery-ia -l app.kubernetes.io/component=microservice --tail=50
```
### Weekly Maintenance
```bash
# Check for completed jobs (clean up if >1 week old)
kubectl get jobs -n bakery-ia
# Review HPA activity
kubectl describe hpa -n bakery-ia
# Check PVC usage
kubectl get pvc -n bakery-ia
df -h # Inside cluster nodes
```
### Monthly Review
- Review resource usage trends
- Assess if VPS upgrade needed
- Check for security updates
- Review and rotate secrets
- Test backup restore procedure
---
## Conclusion
### What Was Achieved
✅ **Production-ready Kubernetes configuration** for 10-tenant pilot
✅ **Proper service dependency management** with initContainers
✅ **Autoscaling configured** for key services (orders, forecasting, notifications)
✅ **Dev/prod overlay separation** with appropriate configurations
✅ **Comprehensive documentation** for deployment and operations
✅ **VPS sizing recommendations** based on actual resource calculations
✅ **Consolidated tooling** (Skaffold with security-first approach)
### Deployment Readiness
**Status**: ✅ **READY FOR PRODUCTION DEPLOYMENT**
The Bakery IA platform is now properly configured for:
- Production VPS deployment (clouding.io or similar)
- 10-tenant pilot program
- Reliable service startup and dependency management
- Automatic scaling under load
- Monitoring and observability (when enabled)
- Future growth to 25+ tenants
### Next Steps
1. ✅ **Provision VPS** at clouding.io (20 GB RAM, 8 vCPU, 200 GB NVMe)
2. ✅ **Deploy to production**: `skaffold run -p prod`
3.**Enable monitoring**: Uncomment in prod overlay and redeploy
4.**Monitor for 2 weeks**: Validate resource usage matches estimates
5.**Onboard first pilot tenant**: Verify end-to-end functionality
6.**Iterate**: Adjust resources based on real-world metrics
---
**Questions or issues?** Refer to:
- [VPS-SIZING-PRODUCTION.md](./VPS-SIZING-PRODUCTION.md) - Resource planning
- [COLIMA-SETUP.md](./COLIMA-SETUP.md) - Local development setup
- [DEPLOYMENT.md](./DEPLOYMENT.md) - Deployment procedures (if exists)
- Bakery IA team Slack or contact DevOps
**Document Version**: 1.0
**Last Updated**: 2025-11-06
**Status**: Complete ✅

View File

@@ -0,0 +1,345 @@
# VPS Sizing for Production Deployment
## Executive Summary
This document provides detailed resource requirements for deploying the Bakery IA platform to a production VPS environment at **clouding.io** for a **10-tenant pilot program** during the first 6 months.
### Recommended VPS Configuration
```
RAM: 20 GB
Processor: 8 vCPU cores
SSD NVMe (Triple Replica): 200 GB
```
**Estimated Monthly Cost**: Contact clouding.io for current pricing
---
## Resource Analysis
### 1. Application Services (18 Microservices)
#### Standard Services (14 services)
Each service configured with:
- **Request**: 256Mi RAM, 100m CPU
- **Limit**: 512Mi RAM, 500m CPU
- **Production replicas**: 2-3 per service (from prod overlay)
Services:
- auth-service (3 replicas)
- tenant-service (2 replicas)
- inventory-service (2 replicas)
- recipes-service (2 replicas)
- suppliers-service (2 replicas)
- orders-service (3 replicas) *with HPA 1-3*
- sales-service (2 replicas)
- pos-service (2 replicas)
- production-service (2 replicas)
- procurement-service (2 replicas)
- orchestrator-service (2 replicas)
- external-service (2 replicas)
- ai-insights-service (2 replicas)
- alert-processor (3 replicas)
**Total for standard services**: ~39 pods
- RAM requests: ~10 GB
- RAM limits: ~20 GB
- CPU requests: ~3.9 cores
- CPU limits: ~19.5 cores
#### ML/Heavy Services (2 services)
**Training Service** (2 replicas):
- Request: 512Mi RAM, 200m CPU
- Limit: 4Gi RAM, 2000m CPU
- Special storage: 10Gi PVC for models, 4Gi temp storage
**Forecasting Service** (3 replicas) *with HPA 1-3*:
- Request: 512Mi RAM, 200m CPU
- Limit: 1Gi RAM, 1000m CPU
**Notification Service** (3 replicas) *with HPA 1-3*:
- Request: 256Mi RAM, 100m CPU
- Limit: 512Mi RAM, 500m CPU
**ML services total**:
- RAM requests: ~2.3 GB
- RAM limits: ~11 GB
- CPU requests: ~1 core
- CPU limits: ~7 cores
### 2. Databases (18 PostgreSQL instances)
Each database:
- **Request**: 256Mi RAM, 100m CPU
- **Limit**: 512Mi RAM, 500m CPU
- **Storage**: 2Gi PVC each
- **Production replicas**: 1 per database
**Total for databases**: 18 instances
- RAM requests: ~4.6 GB
- RAM limits: ~9.2 GB
- CPU requests: ~1.8 cores
- CPU limits: ~9 cores
- Storage: 36 GB
### 3. Infrastructure Services
**Redis** (1 instance):
- Request: 256Mi RAM, 100m CPU
- Limit: 512Mi RAM, 500m CPU
- Storage: 1Gi PVC
- TLS enabled
**RabbitMQ** (1 instance):
- Request: 512Mi RAM, 200m CPU
- Limit: 1Gi RAM, 1000m CPU
- Storage: 2Gi PVC
**Infrastructure total**:
- RAM requests: ~0.8 GB
- RAM limits: ~1.5 GB
- CPU requests: ~0.3 cores
- CPU limits: ~1.5 cores
- Storage: 3 GB
### 4. Gateway & Frontend
**Gateway** (3 replicas):
- Request: 256Mi RAM, 100m CPU
- Limit: 512Mi RAM, 500m CPU
**Frontend** (2 replicas):
- Request: 512Mi RAM, 250m CPU
- Limit: 1Gi RAM, 500m CPU
**Total**:
- RAM requests: ~1.8 GB
- RAM limits: ~3.5 GB
- CPU requests: ~0.8 cores
- CPU limits: ~2.5 cores
### 5. Monitoring Stack (Optional but Recommended)
**Prometheus**:
- Request: 1Gi RAM, 500m CPU
- Limit: 2Gi RAM, 1000m CPU
- Storage: 20Gi PVC
- Retention: 200h
**Grafana**:
- Request: 256Mi RAM, 100m CPU
- Limit: 512Mi RAM, 200m CPU
- Storage: 5Gi PVC
**Jaeger**:
- Request: 256Mi RAM, 100m CPU
- Limit: 512Mi RAM, 200m CPU
**Monitoring total**:
- RAM requests: ~1.5 GB
- RAM limits: ~3 GB
- CPU requests: ~0.7 cores
- CPU limits: ~1.4 cores
- Storage: 25 GB
### 6. External Services (Optional in Production)
**Nominatim** (Disabled by default - can use external geocoding API):
- If enabled: 2Gi/1 CPU request, 4Gi/2 CPU limit
- Storage: 70Gi (50Gi data + 20Gi flatnode)
- **Recommendation**: Use external geocoding service (Google Maps API, Mapbox) for pilot to save resources
---
## Total Resource Summary
### With Monitoring, Without Nominatim (Recommended)
| Resource | Requests | Limits | Recommended VPS |
|----------|----------|--------|-----------------|
| **RAM** | ~21 GB | ~48 GB | **20 GB** |
| **CPU** | ~8.5 cores | ~41 cores | **8 vCPU** |
| **Storage** | ~79 GB | - | **200 GB NVMe** |
### Memory Calculation Details
- Application services: 14.1 GB requests / 34.5 GB limits
- Databases: 4.6 GB requests / 9.2 GB limits
- Infrastructure: 0.8 GB requests / 1.5 GB limits
- Gateway/Frontend: 1.8 GB requests / 3.5 GB limits
- Monitoring: 1.5 GB requests / 3 GB limits
- **Total requests**: ~22.8 GB
- **Total limits**: ~51.7 GB
### Why 20 GB RAM is Sufficient
1. **Requests vs Limits**: Kubernetes uses requests for scheduling. Our total requests (~22.8 GB) fit in 20 GB because:
- Not all services will run at their request levels simultaneously during pilot
- HPA-enabled services (orders, forecasting, notification) start at 1 replica
- Some overhead included in our calculations
2. **Actual Usage**: Production limits are safety margins. Real usage for 10 tenants will be:
- Most services use 40-60% of their limits under normal load
- Pilot traffic is significantly lower than peak design capacity
3. **Cost-Effective Pilot**: Starting with 20 GB allows:
- Room for monitoring and logging
- Comfortable headroom (15-25%)
- Easy vertical scaling if needed
### CPU Calculation Details
- Application services: 5.7 cores requests / 28.5 cores limits
- Databases: 1.8 cores requests / 9 cores limits
- Infrastructure: 0.3 cores requests / 1.5 cores limits
- Gateway/Frontend: 0.8 cores requests / 2.5 cores limits
- Monitoring: 0.7 cores requests / 1.4 cores limits
- **Total requests**: ~9.3 cores
- **Total limits**: ~42.9 cores
### Storage Calculation
- Databases: 36 GB (18 × 2Gi)
- Model storage: 10 GB
- Infrastructure (Redis, RabbitMQ): 3 GB
- Monitoring: 25 GB
- OS and container images: ~30 GB
- Growth buffer: ~95 GB
- **Total**: ~199 GB → **200 GB NVMe recommended**
---
## Scaling Considerations
### Horizontal Pod Autoscaling (HPA)
Already configured for:
1. **orders-service**: 1-3 replicas based on CPU (70%) and memory (80%)
2. **forecasting-service**: 1-3 replicas based on CPU (70%) and memory (75%)
3. **notification-service**: 1-3 replicas based on CPU (70%) and memory (80%)
These services will automatically scale up under load without manual intervention.
### Growth Path for 6-12 Months
If tenant count grows beyond 10:
| Tenants | RAM | CPU | Storage |
|---------|-----|-----|---------|
| 10 | 20 GB | 8 cores | 200 GB |
| 25 | 32 GB | 12 cores | 300 GB |
| 50 | 48 GB | 16 cores | 500 GB |
| 100+ | Consider Kubernetes cluster with multiple nodes |
### Vertical Scaling
If you hit resource limits before adding more tenants:
1. Upgrade RAM first (most common bottleneck)
2. Then CPU if services show high utilization
3. Storage can be expanded independently
---
## Cost Optimization Strategies
### For Pilot Phase (Months 1-6)
1. **Disable Nominatim**: Use external geocoding API
- Saves: 70 GB storage, 2 GB RAM, 1 CPU core
- Cost: ~$5-10/month for external API (Google Maps, Mapbox)
- **Recommendation**: Enable Nominatim only if >50 tenants
2. **Start Without Monitoring**: Add later if needed
- Saves: 25 GB storage, 1.5 GB RAM, 0.7 CPU cores
- **Not recommended** - monitoring is crucial for production
3. **Reduce Database Replicas**: Keep at 1 per service
- Already configured in base
- **Acceptable risk** for pilot phase
### After Pilot Success (Months 6+)
1. **Enable full HA**: Increase database replicas to 2
2. **Add Nominatim**: If external API costs exceed $20/month
3. **Upgrade VPS**: To 32 GB RAM / 12 cores for 25+ tenants
---
## Network and Additional Requirements
### Bandwidth
- Estimated: 2-5 TB/month for 10 tenants
- Includes: API traffic, frontend assets, image uploads, reports
### Backup Strategy
- Database backups: ~10 GB/day (compressed)
- Retention: 30 days
- Additional storage: 300 GB for backups (separate volume recommended)
### Domain & SSL
- 1 domain: `yourdomain.com`
- SSL: Let's Encrypt (free) or wildcard certificate
- Ingress controller: nginx (included in stack)
---
## Deployment Checklist
### Pre-Deployment
- [ ] VPS provisioned with 20 GB RAM, 8 cores, 200 GB NVMe
- [ ] Docker and Kubernetes (k3s or similar) installed
- [ ] Domain DNS configured
- [ ] SSL certificates ready
### Initial Deployment
- [ ] Deploy with `skaffold run -p prod`
- [ ] Verify all pods running: `kubectl get pods -n bakery-ia`
- [ ] Check PVC status: `kubectl get pvc -n bakery-ia`
- [ ] Access frontend and test login
### Post-Deployment Monitoring
- [ ] Set up external monitoring (UptimeRobot, Pingdom)
- [ ] Configure backup schedule
- [ ] Test database backups and restore
- [ ] Load test with simulated tenant traffic
---
## Support and Scaling
### When to Scale Up
Monitor these metrics:
1. **RAM usage consistently >80%** → Upgrade RAM
2. **CPU usage consistently >70%** → Upgrade CPU
3. **Storage >150 GB used** → Upgrade storage
4. **Response times >2 seconds** → Add replicas or upgrade VPS
### Emergency Scaling
If you hit limits suddenly:
1. Scale down non-critical services temporarily
2. Disable monitoring temporarily (not recommended for >1 hour)
3. Increase VPS resources (clouding.io allows live upgrades)
4. Review and optimize resource-heavy queries
---
## Conclusion
The recommended **20 GB RAM / 8 vCPU / 200 GB NVMe** configuration provides:
✅ Comfortable headroom for 10-tenant pilot
✅ Full monitoring and observability
✅ High availability for critical services
✅ Room for traffic spikes (2-3x baseline)
✅ Cost-effective starting point
✅ Easy scaling path as you grow
**Total estimated compute cost**: €40-80/month (check clouding.io current pricing)
**Additional costs**: Domain (~€15/year), external APIs (~€10/month), backups (~€10/month)
**Next steps**:
1. Provision VPS at clouding.io
2. Follow deployment guide in `/docs/DEPLOYMENT.md`
3. Monitor resource usage for first 2 weeks
4. Adjust based on actual metrics