2025-09-27 11:18:13 +02:00
# Bakery IA Kubernetes Configuration
2025-09-28 19:48:05 +02:00
This directory contains Kubernetes manifests for deploying the Bakery IA platform in local development and production environments with HTTPS support using cert-manager and NGINX ingress.
2025-09-27 11:18:13 +02:00
2025-09-28 19:48:05 +02:00
## Quick Start
Deploy the entire platform with these 5 commands:
2025-09-27 11:18:13 +02:00
2025-09-28 13:54:28 +02:00
```bash
2025-09-28 19:48:05 +02:00
# 1. Start Colima with adequate resources
2025-11-06 11:04:50 +01:00
colima start --cpu 6 --memory 12 --disk 120 --runtime docker --profile k8s-local
2025-09-28 13:54:28 +02:00
# 2. Create Kind cluster with permanent localhost access
kind create cluster --config kind-config.yaml
# 3. Install NGINX Ingress Controller
2025-09-28 19:48:05 +02:00
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
kubectl wait --namespace ingress-nginx --for=condition=ready pod --selector=app.kubernetes.io/component=controller --timeout=300s
2025-09-27 11:18:13 +02:00
2025-09-28 13:54:28 +02:00
# 4. Configure permanent localhost access
kubectl patch svc ingress-nginx-controller -n ingress-nginx -p '{"spec":{"type":"NodePort","ports":[{"name":"http","port":80,"targetPort":"http","nodePort":30080},{"name":"https","port":443,"targetPort":"https","nodePort":30443}]}}'
2025-09-28 19:48:05 +02:00
# 5. Deploy with Skaffold
2025-09-28 13:54:28 +02:00
skaffold dev --profile=dev
2025-09-28 19:48:05 +02:00
# 🎉 Access at: https://localhost
2025-09-28 13:54:28 +02:00
```
2025-09-28 19:48:05 +02:00
## Prerequisites
2025-09-28 13:54:28 +02:00
2025-09-28 19:48:05 +02:00
Install the following tools on macOS:
2025-09-27 11:18:13 +02:00
```bash
2025-09-28 19:48:05 +02:00
# Install via Homebrew
2025-09-28 13:54:28 +02:00
brew install colima kind kubectl skaffold
2025-09-27 11:18:13 +02:00
2025-09-28 13:54:28 +02:00
# Verify installations
2025-09-28 19:48:05 +02:00
colima version & & kind version & & kubectl version --client & & skaffold version
2025-09-28 13:54:28 +02:00
```
2025-09-27 11:18:13 +02:00
## Directory Structure
```
infrastructure/kubernetes/
├── base/ # Base Kubernetes resources
│ ├── namespace.yaml # Namespace definition
│ ├── configmap.yaml # Shared configuration
2025-09-28 19:48:05 +02:00
│ ├── secrets.yaml # Base64 encoded secrets
2025-09-28 13:54:28 +02:00
│ ├── ingress-https.yaml # HTTPS ingress rules
2025-09-28 19:48:05 +02:00
│ ├── kustomization.yaml # Base kustomization
│ └── components/ # Individual component manifests
│ ├── cert-manager/ # Certificate management
│ ├── auth/ # Authentication service
│ ├── tenant/ # Tenant management
│ ├── training/ # ML training service
│ ├── forecasting/ # Demand forecasting
│ ├── sales/ # Sales management
│ ├── external/ # External API service
│ ├── notification/ # Notification service
│ ├── inventory/ # Inventory management
│ ├── recipes/ # Recipe management
│ ├── suppliers/ # Supplier management
│ ├── pos/ # Point of sale
│ ├── orders/ # Order management
│ ├── production/ # Production planning
│ ├── alert-processor/ # Alert processing
│ ├── frontend/ # React frontend
│ ├── databases/ # Database deployments
│ └── infrastructure/ # Gateway & monitoring
2025-09-27 11:18:13 +02:00
└── overlays/
2025-09-28 19:48:05 +02:00
└── dev/ # Development environment
├── kustomization.yaml # Dev-specific configuration
└── dev-patches.yaml # Development patches
2025-09-27 11:18:13 +02:00
```
2025-09-28 19:48:05 +02:00
## Access URLs
2025-09-27 11:18:13 +02:00
2025-09-28 19:48:05 +02:00
### Primary Access (Standard Web Ports)
- **Frontend**: https://localhost
- **API Gateway**: https://localhost/api
2025-09-28 13:54:28 +02:00
2025-09-28 19:48:05 +02:00
### Named Host Access (Optional)
Add to `/etc/hosts` for named access:
2025-09-28 13:54:28 +02:00
```bash
echo "127.0.0.1 bakery-ia.local" | sudo tee -a /etc/hosts
echo "127.0.0.1 api.bakery-ia.local" | sudo tee -a /etc/hosts
echo "127.0.0.1 monitoring.bakery-ia.local" | sudo tee -a /etc/hosts
2025-09-27 11:18:13 +02:00
```
2025-09-28 13:54:28 +02:00
Then access via:
2025-09-28 19:48:05 +02:00
- **Frontend**: https://bakery-ia.local
- **API**: https://api.bakery-ia.local
- **Monitoring**: https://monitoring.bakery-ia.local
2025-09-28 13:54:28 +02:00
2025-09-28 19:48:05 +02:00
### Direct Service Access (Development)
- **Frontend**: http://localhost:3000
- **Gateway**: http://localhost:8000
2025-09-28 13:54:28 +02:00
2025-09-28 19:48:05 +02:00
## Development Workflow
2025-09-28 13:54:28 +02:00
2025-09-28 19:48:05 +02:00
### Start Development Environment
2025-09-28 13:54:28 +02:00
```bash
2025-09-28 19:48:05 +02:00
# Start development mode with hot-reload
skaffold dev --profile=dev
2025-09-27 11:18:13 +02:00
2025-09-28 19:48:05 +02:00
# Or one-time deployment
skaffold run --profile=dev
2025-09-27 11:18:13 +02:00
```
2025-09-28 19:48:05 +02:00
### Key Features
- ✅ **Hot-reload development** - Automatic rebuilds on code changes
- ✅ **Permanent localhost access** - No port forwarding needed
- ✅ **HTTPS by default** - Local CA certificates for secure development
- ✅ **Microservices architecture** - All services deployed together
- ✅ **Database management** - PostgreSQL, Redis, and RabbitMQ included
2025-09-27 11:18:13 +02:00
2025-09-28 19:48:05 +02:00
### Monitor and Debug
2025-09-27 11:18:13 +02:00
```bash
# Check all resources
kubectl get all -n bakery-ia
2025-09-28 19:48:05 +02:00
# View logs
kubectl logs -n bakery-ia deployment/auth-service -f
2025-09-27 11:18:13 +02:00
2025-09-28 19:48:05 +02:00
# Check ingress status
kubectl get ingress -n bakery-ia
2025-09-27 11:18:13 +02:00
2025-09-28 19:48:05 +02:00
# Debug certificate issues
kubectl describe certificate bakery-ia-tls-cert -n bakery-ia
2025-09-27 11:18:13 +02:00
```
2025-09-28 19:48:05 +02:00
## Certificate Management
2025-09-27 11:18:13 +02:00
2025-09-28 19:48:05 +02:00
The platform uses cert-manager for automatic HTTPS certificate generation:
2025-09-27 11:18:13 +02:00
2025-09-28 19:48:05 +02:00
- **Local CA**: For development (default)
- **Let's Encrypt Staging**: For testing
- **Let's Encrypt Production**: For production deployments
2025-09-27 11:18:13 +02:00
2025-09-28 19:48:05 +02:00
### Trust Local Certificates
2025-09-27 11:18:13 +02:00
```bash
2025-09-28 19:48:05 +02:00
# Export CA certificate
kubectl get secret local-ca-key-pair -n cert-manager -o jsonpath='{.data.tls\.crt}' | base64 -d > bakery-ia-ca.crt
2025-09-27 11:18:13 +02:00
2025-09-28 19:48:05 +02:00
# Trust in macOS
open bakery-ia-ca.crt
# In Keychain Access, set "bakery-ia-local-ca" to "Always Trust"
2025-09-27 11:18:13 +02:00
```
2025-09-28 19:48:05 +02:00
## Configuration Management
2025-09-27 11:18:13 +02:00
### Secrets
2025-09-28 19:48:05 +02:00
Base64-encoded secrets are stored in `base/secrets.yaml` . For production:
- Use external secret management (HashiCorp Vault, AWS Secrets Manager)
- Never commit real secrets to version control
2025-09-27 11:18:13 +02:00
```bash
2025-09-28 19:48:05 +02:00
# Encode secrets
2025-09-27 11:18:13 +02:00
echo -n "your-secret-value" | base64
2025-09-28 19:48:05 +02:00
# Decode secrets
2025-09-27 11:18:13 +02:00
echo "eW91ci1zZWNyZXQtdmFsdWU=" | base64 -d
```
2025-09-28 19:48:05 +02:00
### Environment Configuration
Development-specific settings are in `overlays/dev/` :
- **Resource limits**: Reduced for local development
- **Image pull policy**: Never (for local images)
- **Debug settings**: Enabled
- **CORS**: Configured for localhost
2025-09-27 11:18:13 +02:00
2025-09-28 19:48:05 +02:00
## Scaling and Resource Management
### Scale Services
```bash
# Scale individual service
kubectl scale -n bakery-ia deployment/auth-service --replicas=3
2025-09-27 11:18:13 +02:00
2025-09-28 19:48:05 +02:00
# Or update kustomization.yaml replicas section
```
2025-09-27 11:18:13 +02:00
2025-09-28 19:48:05 +02:00
### Resource Configuration
Development environment uses minimal resources:
- **Databases**: 64Mi-256Mi memory, 25m-200m CPU
- **Services**: 64Mi-256Mi memory, 25m-200m CPU
- **Training Service**: 256Mi-1Gi memory (ML workloads)
2025-09-27 11:18:13 +02:00
## Troubleshooting
### Common Issues
2025-09-28 19:48:05 +02:00
1. **Images not found**
```bash
# Build images with Skaffold
skaffold build --profile=dev
```
2. **Database corruption after restart**
```bash
# Delete corrupted PVC and restart
kubectl delete pod -n bakery-ia -l app.kubernetes.io/name=inventory-db
kubectl delete pvc -n bakery-ia inventory-db-pvc
```
3. **HTTPS certificate not issued**
```bash
# Check cert-manager logs
kubectl logs -n cert-manager deployment/cert-manager
kubectl describe certificate bakery-ia-tls-cert -n bakery-ia
```
4. **Port conflicts**
```bash
# Check what's using ports 80/443
sudo lsof -i :80 -i :443
```
### Debug Commands
2025-09-28 13:54:28 +02:00
```bash
2025-09-28 19:48:05 +02:00
# Get cluster events
2025-09-27 11:18:13 +02:00
kubectl get events -n bakery-ia --sort-by='.firstTimestamp'
2025-09-28 19:48:05 +02:00
# Resource usage
2025-09-27 11:18:13 +02:00
kubectl top pods -n bakery-ia
kubectl top nodes
2025-09-28 13:54:28 +02:00
2025-09-28 19:48:05 +02:00
# Execute in pod
kubectl exec -n bakery-ia -it < pod-name > -- bash
2025-09-27 11:18:13 +02:00
```
2025-09-28 19:48:05 +02:00
## Cleanup
2025-09-28 13:54:28 +02:00
2025-09-28 19:48:05 +02:00
### Quick Cleanup
2025-09-28 13:54:28 +02:00
```bash
2025-09-28 19:48:05 +02:00
# Stop Skaffold (Ctrl+C or)
skaffold delete --profile=dev
2025-09-28 13:54:28 +02:00
```
2025-09-28 19:48:05 +02:00
### Complete Cleanup
2025-09-28 13:54:28 +02:00
```bash
2025-09-28 19:48:05 +02:00
# Delete everything
kubectl delete namespace bakery-ia
kind delete cluster --name bakery-ia-local
colima stop --profile k8s-local
2025-09-28 13:54:28 +02:00
```
2025-09-28 19:48:05 +02:00
### Restart Sequence
2025-09-28 13:54:28 +02:00
```bash
2025-09-28 19:48:05 +02:00
# Post-restart startup
2025-11-06 11:04:50 +01:00
colima start --cpu 6 --memory 12 --disk 120 --runtime docker --profile k8s-local
2025-09-28 19:48:05 +02:00
kind create cluster --config kind-config.yaml
2025-09-28 13:54:28 +02:00
skaffold dev --profile=dev
```
2025-09-28 19:48:05 +02:00
## Production Considerations
2025-09-28 13:54:28 +02:00
2025-09-28 19:48:05 +02:00
For production deployment:
2025-09-28 13:54:28 +02:00
2025-09-28 19:48:05 +02:00
- **Security**: Implement RBAC, network policies, pod security standards
- **Monitoring**: Deploy Prometheus, Grafana, and alerting
- **Backup**: Database backup strategies
- **High Availability**: Multi-replica deployments with anti-affinity
- **External Secrets**: Use managed secret services
- **TLS**: Production Let's Encrypt certificates
- **CI/CD**: Automated deployment pipelines
2025-09-28 13:54:28 +02:00
2025-09-28 19:48:05 +02:00
## Next Steps
2025-09-28 13:54:28 +02:00
2025-09-28 19:48:05 +02:00
1. Add comprehensive monitoring and logging
2. Implement automated testing
3. Set up CI/CD pipelines
4. Add health checks and metrics endpoints
5. Implement proper backup strategies