feat: topology, and improves handling

This commit is contained in:
2026-02-17 18:12:02 +07:00
parent e8dbefde43
commit d14f043e7c
145 changed files with 4213 additions and 2861 deletions

View File

@@ -1,6 +1,5 @@
#!/bin/bash
# Minikura Installer
# This script installs Minikura on a Kubernetes cluster
set -e
@@ -16,103 +15,47 @@ echo ""
# Check prerequisites
echo "-> Checking prerequisites..."
if ! command -v kubectl &> /dev/null; then
echo "[ERROR] kubectl not found. Please install kubectl first."
exit 1
echo "[WARN] kubectl not found. Skipping k8s setup."
echo "[INFO] Install kubectl and run 'bash scripts/install.sh' manually when ready."
exit 0
fi
if ! kubectl cluster-info &> /dev/null; then
echo "[ERROR] Cannot connect to Kubernetes cluster. Please check your kubeconfig."
exit 1
echo "[WARN] Cannot connect to Kubernetes cluster. Skipping k8s setup."
echo "[INFO] Run 'bash scripts/install.sh' manually when cluster is ready."
exit 0
fi
echo "[OK] kubectl found"
echo "[OK] Connected to Kubernetes cluster"
echo ""
# Step 1: Create namespace
# Create namespace
echo "-> Creating namespace: $NAMESPACE"
if kubectl get namespace $NAMESPACE &>/dev/null; then
echo "[OK] Namespace already exists"
else
kubectl create namespace $NAMESPACE
echo "[OK] Namespace created"
fi
kubectl create namespace $NAMESPACE --dry-run=client -o yaml | kubectl apply -f -
echo ""
# Step 2: Apply RBAC
echo "-> Setting up RBAC (Service Accounts & Permissions)"
kubectl apply -f "$PROJECT_ROOT/k8s/rbac/dev-rbac.yaml"
# Apply RBAC (single SA for both backend and operator)
echo "-> Setting up RBAC (minikura-operator ServiceAccount)"
kubectl apply -f "$PROJECT_ROOT/k8s/rbac/operator-rbac.yaml"
echo "[OK] RBAC configured"
echo " • minikura-dev (read-only)"
echo " • minikura-operator (full access)"
echo ""
# Step 3: Wait for tokens
echo "-> Waiting for service account tokens..."
sleep 3
DEV_TOKEN=""
OPERATOR_TOKEN=""
for i in {1..10}; do
DEV_TOKEN=$(kubectl get secret minikura-dev-token -n $NAMESPACE -o jsonpath='{.data.token}' 2>/dev/null | base64 -d || echo "")
OPERATOR_TOKEN=$(kubectl get secret minikura-operator-token -n $NAMESPACE -o jsonpath='{.data.token}' 2>/dev/null | base64 -d || echo "")
if [ -n "$DEV_TOKEN" ] && [ -n "$OPERATOR_TOKEN" ]; then
break
fi
sleep 2
done
if [ -z "$OPERATOR_TOKEN" ]; then
echo "[WARNING] Tokens not ready yet. You may need to run 'bun run k8s:token' later."
else
echo "[OK] Service account tokens generated"
fi
# CRD info
echo "-> Custom Resource Definitions"
echo " CRDs are auto-created when the operator starts (ENABLE_CRD_REFLECTION=true)"
echo ""
# Step 4: CRD Information
echo "-> Custom Resource Definitions (CRDs)"
echo " CRDs will be automatically created when the operator starts"
echo " with ENABLE_CRD_REFLECTION=true (default)"
echo ""
echo " The operator will create:"
echo " • MinecraftServer CRD"
echo " • ReverseProxyServer CRD"
echo ""
# Step 5: Configuration
echo "╔════════════════════════════════════════════════╗"
echo "║ Installation Complete ║"
echo "╚════════════════════════════════════════════════╝"
echo ""
echo "Kubernetes resources created:"
echo "Resources created:"
echo " [OK] Namespace: $NAMESPACE"
echo " [OK] Service Accounts: minikura-dev, minikura-operator"
echo " [OK] RBAC: ClusterRoles and ClusterRoleBindings"
echo " [OK] Tokens: Ready for authentication"
echo " [OK] ServiceAccount: minikura-operator"
echo " [OK] ClusterRole + ClusterRoleBinding"
echo ""
echo "Next steps:"
echo ""
echo "1. Configure environment variables (.env):"
echo " KUBERNETES_NAMESPACE=\"$NAMESPACE\""
echo " KUBERNETES_SKIP_TLS_VERIFY=\"true\" # For local dev only"
echo " KUBERNETES_SERVICE_ACCOUNT_TOKEN=\"<token>\""
echo ""
echo " To get the token automatically:"
echo " $ bun run k8s:token"
echo ""
echo "2. Start the operator:"
echo " $ bun run k8s:dev"
echo ""
echo " The operator will automatically:"
echo " - Create CRDs (MinecraftServer, ReverseProxyServer)"
echo " - Sync database state to Kubernetes"
echo " - Watch for changes and update resources"
echo ""
echo "3. Start the backend:"
echo " $ bun run dev"
echo ""
echo "For production deployment, see docs/DEPLOYMENT.md"
echo " bun run dev - Start backend + web"
echo " bun run k8s:dev - Start K8s operator"
echo ""