Date: January 26, 2026
Phase: Database Schema
Status: Complete
- ✅ Created Alembic migration
20260126_1600_create_kubernetes_tables.py - ✅ Executed migration successfully in PostgreSQL
- ✅ All tables, partitions, indexes, and views created
-
k8s_clusters - Kubernetes cluster registry
- Stores encrypted kubeconfig
- Tracks cluster health and status
- Provider metadata (EKS, GKE, AKS, k3s, vanilla)
- Cost tracking per cluster
-
k8s_namespaces - Namespace tracking
- Resource quotas and limits
- Team/cost-center attribution
- Usage metrics (CPU, memory, pods)
-
k8s_nodes - Cluster node inventory
- Capacity and allocatable resources
- Current usage metrics
- Labels, taints, conditions
-
k8s_deployments - Deployment tracking
- Replica counts and health status
- Container specifications
- Deployment strategies
-
k8s_pods (PARTITIONED) - Pod instance tracking
- 12 monthly partitions for 2026
- Pod lifecycle and status
- Resource requests/limits
- Container status tracking
-
k8s_resource_metrics (PARTITIONED) - Time-series metrics
- 12 monthly partitions for 2026
- CPU, memory, network, storage metrics
- Multi-level (cluster, namespace, deployment, pod, node)
- OOM kills and restart tracking
-
k8s_helm_releases - Helm chart deployments
- Chart name and version
- Release status and revision
- Values configuration
-
k8s_cost_attribution - Cost tracking
- Hourly and daily cost aggregation
- Resource-level breakdown (CPU, memory, storage, network)
- Team and cost-center attribution
- ✅ 12 partitions for
k8s_pods(Jan-Dec 2026) - ✅ 12 partitions for
k8s_resource_metrics(Jan-Dec 2026)
-
v_k8s_cluster_health - Cluster health dashboard
- Aggregated health metrics
- Node and deployment counts
- Resource usage totals
- Cost estimates
-
v_k8s_namespace_costs - Namespace cost summary
- Last 30 days cost totals
- Average daily costs
- Resource usage hours
- Team attribution
- Cluster organization and status lookups
- Namespace filtering by team/cost-center
- Deployment health monitoring
- Time-series partition pruning
- Cost attribution queries
-- Total K8s Tables: 32
- 8 core tables
- 24 partition tables (12 pods + 12 metrics)
-- Total Indexes: 30+
-- Total Views: 2
-- Total Constraints: 15+ (FK, UNIQUE)# All tables created
docker exec ops-center-postgresql psql -U unicorn -d unicorn_db -c "\dt k8s_*"
# Partition verification
docker exec ops-center-postgresql psql -U unicorn -d unicorn_db -c "
SELECT tablename FROM pg_tables
WHERE tablename LIKE 'k8s_pods_%'
ORDER BY tablename;"
# Views verification
docker exec ops-center-postgresql psql -U unicorn -d unicorn_db -c "\dv v_k8s_*"
# Index count
docker exec ops-center-postgresql psql -U unicorn -d unicorn_db -c "
SELECT COUNT(*) FROM pg_indexes
WHERE tablename LIKE 'k8s_%';"-
Dependencies
# Add to backend/requirements.txt kubernetes==29.0.0 kubernetes-asyncio==29.0.0 -
Core Files to Create
backend/k8s_cluster_manager.py- Business logicbackend/k8s_sync_worker.py- Background sync (30s)backend/k8s_cost_calculator.py- Cost attributionbackend/k8s_api.py- REST API (19 endpoints)
-
Key Features
- Cluster registration with kubeconfig encryption
- Real-time health monitoring
- Namespace/deployment/pod synchronization
- Metrics collection and storage
- Cost calculation engine
-
Integration Points
- Add router to
server.py - Start workers in
startup_event() - Stop workers in
shutdown_event()
- Add router to
File: alembic/versions/20260126_1600_create_kubernetes_tables.py
Revision: 20260126_1600
Previous: 20260126_1500 (Fleet Management)
Execution: Direct SQL via Docker exec
Rollback Available: Yes, downgrade() function drops all tables
-
Partitioning Strategy: Monthly partitions for pods and metrics
- Efficient pruning of old data
- Optimized time-range queries
- Automatic partition routing
-
Cost Attribution: Separate table with hourly/daily aggregation
- Flexible team/cost-center tracking
- Historical cost analysis
- Budget forecasting support
-
Encryption: Kubeconfig stored encrypted
- Uses BYOK_ENCRYPTION_KEY
- Never exposed in API responses
- Decrypted only for K8s API calls
-
Views: Pre-computed aggregations
- Fast dashboard queries
- No N+1 query problems
- Consistent data representation
Phase 1 Complete! Ready for Phase 2: Backend Implementation 🚀