Files
Minikura/scripts/install.sh
T

81 lines
3.3 KiB
Bash
Raw Normal View History

2026-08-13 03:29:29 +07:00
#!/usr/bin/env bash
set -euo pipefail
2026-02-13 15:52:13 +07:00
NAMESPACE="${KUBERNETES_NAMESPACE:-minikura}"
2026-08-13 03:29:29 +07:00
OPERATOR_IMAGE="${OPERATOR_IMAGE:-minikura-operator:latest}"
ROLLOUT_TIMEOUT="${ROLLOUT_TIMEOUT:-120s}"
2026-02-13 15:52:13 +07:00
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
2026-08-13 03:29:29 +07:00
case "$NAMESPACE" in
''|*[!a-z0-9-]*|-*|*-) echo "[ERROR] KUBERNETES_NAMESPACE must be a DNS label" >&2; exit 1 ;;
esac
if (( ${#NAMESPACE} > 63 )); then
echo "[ERROR] KUBERNETES_NAMESPACE must not exceed 63 characters" >&2
exit 1
fi
2026-02-13 15:52:13 +07:00
echo "╔════════════════════════════════════════════════╗"
echo "║ Minikura Kubernetes Installer ║"
echo "╚════════════════════════════════════════════════╝"
echo ""
echo "-> Checking prerequisites..."
if ! command -v kubectl &> /dev/null; then
2026-08-13 03:29:29 +07:00
echo "[ERROR] kubectl is required" >&2
exit 1
2026-02-13 15:52:13 +07:00
fi
if ! kubectl cluster-info &> /dev/null; then
2026-08-13 03:29:29 +07:00
echo "[ERROR] Cannot connect to the current Kubernetes cluster" >&2
exit 1
2026-02-13 15:52:13 +07:00
fi
echo "[OK] kubectl found"
echo "[OK] Connected to Kubernetes cluster"
echo ""
echo "-> Creating namespace: $NAMESPACE"
2026-08-13 03:29:29 +07:00
kubectl create namespace "$NAMESPACE" --dry-run=client -o yaml | kubectl apply -f -
2026-02-13 15:52:13 +07:00
echo ""
2026-08-13 02:18:51 +07:00
echo "-> Installing operator CRDs"
2026-08-13 03:29:29 +07:00
kubectl apply -f "$PROJECT_ROOT/operator/config/crd"
2026-08-13 02:18:51 +07:00
echo "[OK] CRDs installed"
2026-02-13 15:52:13 +07:00
echo ""
2026-08-13 03:29:29 +07:00
echo "-> Configuring operator and backend RBAC"
# Remove bindings created by older releases before replacing them with namespaced access.
kubectl delete clusterrolebinding minikura-operator-rolebinding \
minikura-backend-operator-resources --ignore-not-found
kubectl delete clusterrole minikura-backend-operator-resources --ignore-not-found
2026-08-13 02:18:51 +07:00
kubectl apply -f "$PROJECT_ROOT/operator/config/rbac/role.yaml"
2026-08-13 03:29:29 +07:00
sed "s/namespace: minikura/namespace: $NAMESPACE/g" \
"$PROJECT_ROOT/operator/config/rbac/service_account.yaml" | kubectl apply -n "$NAMESPACE" -f -
sed "s/namespace: minikura/namespace: $NAMESPACE/g" \
"$PROJECT_ROOT/operator/config/rbac/backend.yaml" | kubectl apply -n "$NAMESPACE" -f -
echo "[OK] RBAC configured"
echo ""
echo "-> Deploying operator: $OPERATOR_IMAGE"
kubectl set image -f "$PROJECT_ROOT/operator/config/manager/deployment.yaml" \
operator="$OPERATOR_IMAGE" --local -o yaml | kubectl apply -n "$NAMESPACE" -f -
kubectl rollout restart -n "$NAMESPACE" deployment/minikura-operator
kubectl rollout status -n "$NAMESPACE" deployment/minikura-operator --timeout="$ROLLOUT_TIMEOUT"
echo "[OK] Operator deployed"
2026-02-13 15:52:13 +07:00
echo ""
echo "╔════════════════════════════════════════════════╗"
echo "║ Installation Complete ║"
echo "╚════════════════════════════════════════════════╝"
echo ""
2026-02-17 18:12:02 +07:00
echo "Resources created:"
2026-02-13 15:52:13 +07:00
echo " [OK] Namespace: $NAMESPACE"
2026-02-17 18:12:02 +07:00
echo " [OK] ServiceAccount: minikura-operator"
2026-08-13 03:29:29 +07:00
echo " [OK] ServiceAccount: minikura-backend"
echo " [OK] Operator Deployment: $OPERATOR_IMAGE"
2026-02-13 15:52:13 +07:00
echo ""
echo "Next steps:"
2026-08-13 03:29:29 +07:00
echo " Configure an in-cluster backend Deployment to use serviceAccountName: minikura-backend"
2026-02-13 15:52:13 +07:00
echo ""