Unify past-sessions naming format
Format: YYYY-MM-DD-description.md - 2026-01-19-infrastructure-deployment.md - 2026-01-19-backend-api-implementation.md (in progress) Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
361
past-sessions/2026-01-19-infrastructure-deployment.md
Normal file
361
past-sessions/2026-01-19-infrastructure-deployment.md
Normal file
@@ -0,0 +1,361 @@
|
||||
# 🎉 Sesión 1 - Infraestructura Kubernetes HA
|
||||
|
||||
**Fecha**: 2026-01-19
|
||||
**Duración**: ~8 horas
|
||||
**Participantes**: Hector + Claude Code
|
||||
**Enfoque**: Learn by doing - Infraestructura desde cero
|
||||
|
||||
---
|
||||
|
||||
## 🎯 Objetivos Completados
|
||||
|
||||
### 1. Cluster Kubernetes HA en CubePath
|
||||
✅ 3 Control Planes (etcd HA)
|
||||
✅ 3 Workers (48 vCPU, 104 GB RAM)
|
||||
✅ 2 Load Balancers (HAProxy)
|
||||
✅ Red privada 10.100.0.0/24
|
||||
✅ K3s v1.35.0+k3s1 (última versión)
|
||||
|
||||
**Ubicación**: Houston, Texas (us-hou-1)
|
||||
**Costo**: $148/mes
|
||||
|
||||
### 2. Storage HA con Longhorn
|
||||
✅ Longhorn v1.8.0 instalado
|
||||
✅ 3 réplicas por volumen
|
||||
✅ StorageClass default configurado
|
||||
✅ Tolera pérdida de 2 workers
|
||||
|
||||
### 3. Networking y DNS
|
||||
✅ DNS configurado: *.fuq.tv → 2 Load Balancers
|
||||
✅ HAProxy balanceando HTTP/HTTPS a workers
|
||||
✅ Nginx Ingress Controller instalado
|
||||
✅ Cert-Manager + Let's Encrypt (TLS automático)
|
||||
✅ Todos los servicios con HTTPS funcional
|
||||
|
||||
### 4. Plataforma Base
|
||||
✅ MariaDB 11.4 LTS con storage HA (20Gi)
|
||||
✅ Redis 7 desplegado
|
||||
✅ Gitea 1.25.3 instalado y configurado
|
||||
✅ Container Registry habilitado en Gitea
|
||||
✅ ArgoCD instalado (configuración pendiente)
|
||||
|
||||
### 5. CI/CD
|
||||
✅ Gitea Actions Runner con Docker-in-Docker
|
||||
✅ Workflow automático configurado
|
||||
✅ Secrets para registry configurados
|
||||
✅ Build automático en cada push
|
||||
|
||||
### 6. Backend Inicial
|
||||
✅ Estructura del proyecto creada
|
||||
✅ Bun 1.3.6 configurado
|
||||
✅ Database schema (projects, agents, tasks) con Drizzle ORM
|
||||
✅ Auto-migrations implementadas
|
||||
✅ Dockerfile multi-stage creado
|
||||
✅ Repositorio en Gitea: https://git.fuq.tv/admin/aiworker-backend
|
||||
|
||||
### 7. Documentación Completa
|
||||
✅ 50+ archivos de documentación creados
|
||||
✅ Guías centralizadas (GITEA-GUIDE, K8S-CLUSTER, DEVELOPMENT-WORKFLOW)
|
||||
✅ ROADMAP y NEXT-SESSION para continuar
|
||||
✅ CLAUDE.md para agentes IA
|
||||
✅ Todo pusheado a Gitea
|
||||
|
||||
---
|
||||
|
||||
## 🛠️ Tecnologías Instaladas
|
||||
|
||||
| Software | Versión | Propósito |
|
||||
|----------|---------|-----------|
|
||||
| K3s | v1.35.0+k3s1 | Kubernetes distribution |
|
||||
| Longhorn | v1.8.0 | Distributed storage |
|
||||
| MariaDB | 11.4 LTS | Database |
|
||||
| Redis | 7 | Cache/queues |
|
||||
| Gitea | 1.25.3 | Git + Registry |
|
||||
| Nginx Ingress | latest | HTTP routing |
|
||||
| Cert-Manager | v1.16.2 | TLS automation |
|
||||
| HAProxy | 2.8.16 | Load balancing |
|
||||
| Bun | 1.3.6 | Runtime |
|
||||
| Drizzle ORM | 0.45.1 | Database ORM |
|
||||
|
||||
---
|
||||
|
||||
## 📝 Aprendizajes Clave
|
||||
|
||||
### Lo que funcionó bien ✅
|
||||
|
||||
1. **CubeCLI**: Gestión de VPS muy simple
|
||||
2. **K3s con instalación manual**: Control total del proceso
|
||||
3. **Longhorn para storage HA**: Instalación directa, UI visual
|
||||
4. **Gitea todo-en-uno**: Git + Registry + Actions integrado
|
||||
5. **Bun.serve() nativo**: Más simple que Express
|
||||
6. **TCP probes**: Mejor que exec para health checks
|
||||
7. **Red privada desde inicio**: Mejor performance
|
||||
|
||||
### Challenges Resueltos 💪
|
||||
|
||||
1. **K3s con red privada**: Usar `--node-ip` y `--flannel-iface eth1`
|
||||
2. **TLS SANs**: Incluir todas las IPs (públicas y privadas) para HA
|
||||
3. **Gitea INSTALL_LOCK**: Variable de entorno sobreescribía archivo
|
||||
4. **MariaDB health probes**: mysqladmin no disponible → usar TCP
|
||||
5. **Gitea Actions DinD**: Volumen compartido `/docker/docker.sock`
|
||||
6. **Dockerfile lockfile**: `bun.lockb` → `bun.lock`
|
||||
|
||||
### Decisiones Técnicas 🎯
|
||||
|
||||
**Por qué estas tecnologías**:
|
||||
|
||||
- **MariaDB vs MySQL**: LTS más largo, mejor comunidad
|
||||
- **Bun.serve() vs Express**: Nativo, más rápido, menos deps
|
||||
- **Longhorn vs NFS**: HA real con replicación
|
||||
- **Gitea vs GitLab**: Más ligero, registry incluido
|
||||
- **K3s vs K8s**: Más simple, menos overhead
|
||||
- **DNS round-robin vs Keepalived**: Más simple, funciona igual
|
||||
- **Gitea Actions vs externos**: Integrado, self-hosted
|
||||
|
||||
---
|
||||
|
||||
## 🔧 Configuración Realizada
|
||||
|
||||
### CubePath
|
||||
- Proyecto: AiWorker (ID: 875)
|
||||
- Red: k8s-cluster-network (10.100.0.0/24, ID: 70)
|
||||
- SSH Key: Hectorv2 (ID: 35)
|
||||
|
||||
### Kubernetes
|
||||
- K3s token generado y guardado
|
||||
- Kubeconfig: `~/.kube/aiworker-config`
|
||||
- Namespaces creados: control-plane, agents, gitea, gitea-actions, argocd, etc.
|
||||
|
||||
### Gitea
|
||||
- Usuario admin creado (admin/admin123)
|
||||
- Token full-access: `159a5de2a16d15f33e388b55b1276e431dbca3f3`
|
||||
- Token registry: `7401126cfb56ab2aebba17755bdc968c20768c27`
|
||||
- Container Registry habilitado
|
||||
- Actions Runner registrado
|
||||
|
||||
### Storage
|
||||
- Longhorn StorageClass: default
|
||||
- Réplicas: 3
|
||||
- PVCs: mariadb-pvc (20Gi), gitea-data (50Gi)
|
||||
|
||||
### DNS
|
||||
- *.fuq.tv → 108.165.47.221, 108.165.47.203
|
||||
- *.r.fuq.tv → Same
|
||||
- Email cert-manager: hector+aiworker@teamsuqad.io
|
||||
|
||||
---
|
||||
|
||||
## 🚀 URLs Funcionales
|
||||
|
||||
| Servicio | URL | Estado |
|
||||
|----------|-----|--------|
|
||||
| Gitea | https://git.fuq.tv | ✅ Funcional |
|
||||
| ArgoCD | https://argocd.fuq.tv | ✅ Instalado |
|
||||
| Longhorn | https://longhorn.fuq.tv | ✅ Funcional |
|
||||
| Test App | https://test.fuq.tv | ✅ Funcional |
|
||||
| HAProxy Stats | http://108.165.47.221:8404/stats | ✅ Funcional |
|
||||
| Backend Repo | https://git.fuq.tv/admin/aiworker-backend | ✅ Creado |
|
||||
| Docs Repo | https://git.fuq.tv/admin/aiworker | ✅ Creado |
|
||||
|
||||
---
|
||||
|
||||
## 📊 Estado Final
|
||||
|
||||
### Progreso del Proyecto
|
||||
```
|
||||
Infraestructura: ████████████████████ 100%
|
||||
Plataforma: ████████████████████ 100%
|
||||
Backend: ████░░░░░░░░░░░░░░░░ 20%
|
||||
Frontend: ░░░░░░░░░░░░░░░░░░░░ 0%
|
||||
Agentes: ░░░░░░░░░░░░░░░░░░░░ 0%
|
||||
GitOps: ██░░░░░░░░░░░░░░░░░░ 10%
|
||||
──────────────────────────────────────────────
|
||||
Total: ██████░░░░░░░░░░░░░░ 26%
|
||||
```
|
||||
|
||||
### Cluster Health
|
||||
- 6 nodos Ready
|
||||
- Todos los pods system Running
|
||||
- Storage healthy (3 réplicas)
|
||||
- Ingress respondiendo
|
||||
- TLS automático funcionando
|
||||
|
||||
### Repositorios Creados
|
||||
- aiworker (documentación)
|
||||
- aiworker-backend (código backend)
|
||||
|
||||
---
|
||||
|
||||
## 📁 Archivos Creados Esta Sesión
|
||||
|
||||
### Raíz del Proyecto
|
||||
- README.md - Punto de entrada
|
||||
- CLAUDE.md - Para agentes IA
|
||||
- K8S-CLUSTER.md - Info cluster (antes CLUSTER-READY.md)
|
||||
- CLUSTER-CREDENTIALS.md - Credenciales sensibles
|
||||
- GITEA-GUIDE.md - Todo sobre Gitea
|
||||
- DEVELOPMENT-WORKFLOW.md - Cómo trabajamos
|
||||
- ROADMAP.md - Plan general
|
||||
- NEXT-SESSION.md - Próximos pasos
|
||||
- QUICK-REFERENCE.md - Comandos rápidos
|
||||
- TROUBLESHOOTING.md - Debug
|
||||
- AGENT-GUIDE.md - Para agentes operar K8s
|
||||
- CLUSTER-SETUP-COMPLETE.md - Setup detallado
|
||||
- .gitignore - Archivos a ignorar
|
||||
|
||||
### Scripts
|
||||
- scripts/install-k3s-cluster.sh - Instalación reproducible
|
||||
- scripts/setup-load-balancers.sh - HAProxy setup
|
||||
|
||||
### Backend
|
||||
- Estructura completa src/
|
||||
- package.json con dependencias
|
||||
- Drizzle schema (projects, agents, tasks)
|
||||
- Auto-migrations
|
||||
- Dockerfile
|
||||
- .gitea/workflows/build.yml
|
||||
|
||||
### Documentación Técnica (docs/)
|
||||
**40+ archivos** en 6 carpetas:
|
||||
- 01-arquitectura/ (4 archivos)
|
||||
- 02-backend/ (6 archivos)
|
||||
- 03-frontend/ (5 archivos)
|
||||
- 04-kubernetes/ (5 archivos)
|
||||
- 05-agents/ (4 archivos)
|
||||
- 06-deployment/ (4 archivos)
|
||||
- CONTAINER-REGISTRY.md
|
||||
|
||||
---
|
||||
|
||||
## 🎓 Metodología: Learn by Doing
|
||||
|
||||
### Proceso Seguido
|
||||
|
||||
1. **Desplegar primero, documentar después**
|
||||
2. **Probar cada componente antes de continuar**
|
||||
3. **Comandos manuales → Scripts reproducibles**
|
||||
4. **Errores como aprendizaje** (migrations, probes, DinD)
|
||||
5. **Verificación constante** (curl, kubectl, logs)
|
||||
|
||||
### Comandos Ejecutados (~200+)
|
||||
- CubeCLI: create VPS, networks, projects
|
||||
- SSH: Instalación K3s en cada nodo
|
||||
- kubectl: Deploy, verificar, logs
|
||||
- curl: Test endpoints, API calls
|
||||
- git: Commits, push
|
||||
|
||||
---
|
||||
|
||||
## 💡 Tips para Próximas Sesiones
|
||||
|
||||
### DO ✅
|
||||
- Migrations automáticas en la app
|
||||
- Use Bun native APIs
|
||||
- Port-forward solo para testing
|
||||
- Verify builds in Gitea Actions UI
|
||||
- Check logs frequently
|
||||
- Use TCP probes for databases
|
||||
- Keep documentation updated
|
||||
|
||||
### DON'T ❌
|
||||
- Port-forward for migrations
|
||||
- Use Express (use Bun.serve())
|
||||
- Manual migrations
|
||||
- Exec probes for MariaDB
|
||||
- Skip verification steps
|
||||
|
||||
---
|
||||
|
||||
## 🔗 Referencias Útiles de Esta Sesión
|
||||
|
||||
### Comandos Frecuentes
|
||||
```bash
|
||||
# Cluster
|
||||
export KUBECONFIG=~/.kube/aiworker-config
|
||||
kubectl get nodes
|
||||
|
||||
# Gitea
|
||||
open https://git.fuq.tv
|
||||
|
||||
# Actions
|
||||
open https://git.fuq.tv/admin/aiworker-backend/actions
|
||||
|
||||
# Logs
|
||||
kubectl logs -n gitea-actions deployment/gitea-runner -c runner
|
||||
```
|
||||
|
||||
### Troubleshooting
|
||||
- Port-forward issues → Usar IPs directas
|
||||
- DinD problems → Volume compartido `/docker/`
|
||||
- Build fails → Check runner logs
|
||||
- Image pull fails → Verify gitea-registry secret
|
||||
|
||||
---
|
||||
|
||||
## 📈 Métricas de la Sesión
|
||||
|
||||
- **Servidores creados**: 8 VPS
|
||||
- **Comandos ejecutados**: ~200
|
||||
- **Líneas de código**: ~2,000
|
||||
- **Archivos creados**: 50+
|
||||
- **Repositorios Git**: 2
|
||||
- **Deployments K8s**: 10+
|
||||
- **Documentos markdown**: 50+
|
||||
|
||||
---
|
||||
|
||||
## 🎯 Entregables
|
||||
|
||||
✅ Cluster K8s HA funcional
|
||||
✅ Plataforma completa (Gitea, DB, Redis)
|
||||
✅ CI/CD automático operativo
|
||||
✅ Backend inicializado
|
||||
✅ Documentación exhaustiva
|
||||
✅ Scripts reproducibles
|
||||
✅ Todo en Git
|
||||
|
||||
---
|
||||
|
||||
## ➡️ Handoff a Sesión 2
|
||||
|
||||
### Estado al Final de Sesión 1
|
||||
- Cluster: 100% funcional
|
||||
- Backend: 20% completado
|
||||
- Siguiente: Implementar API routes
|
||||
|
||||
### Checklist para Sesión 2
|
||||
Ver `NEXT-SESSION.md` (será actualizado por Hector)
|
||||
|
||||
### Bloqueadores Conocidos
|
||||
- ⚠️ Gitea Actions DinD puede fallar ocasionalmente → Restart runner
|
||||
- ⚠️ ArgoCD instalado pero no configurado
|
||||
- ⚠️ Frontend sin inicializar
|
||||
|
||||
### Quick Start Sesión 2
|
||||
```bash
|
||||
export KUBECONFIG=~/.kube/aiworker-config
|
||||
kubectl get nodes
|
||||
cd backend && bun run dev
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🎊 Highlights
|
||||
|
||||
**Logros principales**:
|
||||
- De 0 a cluster HA funcional en una sesión
|
||||
- Storage distribuido con HA real
|
||||
- TLS automático en todo
|
||||
- CI/CD funcionando
|
||||
- 50+ documentos creados
|
||||
|
||||
**Momento WOW**:
|
||||
Cuando el flujo completo funcionó:
|
||||
```
|
||||
curl https://test.fuq.tv → 200 OK con TLS válido
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
**Próxima sesión**: Completar Backend API y MCP Server
|
||||
**Documentado en**: `NEXT-SESSION.md` (actualizado por Hector)
|
||||
Reference in New Issue
Block a user