A powerful, enterprise-grade multi-tenancy toolkit for modern SaaS applications, featuring a robust microservices architecture.
- Database-per-tenant architecture
- Robust authentication & authorization
- Resource quotas and rate limiting
- Database Layer: High-performance SurrealDB service powered by Rust/Axum
- Application Layer: Go-based microservices with clean architecture
- Infrastructure: Container orchestration with Podman/Kubernetes
- Gateway: Advanced request routing with NGINX
- Seamless tenant management
- Horizontal scalability
- Zero-trust security model
- Real-time analytics
- Infrastructure as Code (IaC)
- Sub-millisecond tenant routing
- Automatic failover
- Load balancing
- Connection pooling
This project implements a tenant service using Rust, SurrealDB, and Kubernetes, with Terraform for infrastructure management.
tenancyship/
βββ db-service/ # SurrealDB service with Rust/Axum
β βββ src/ # Rust source code
β βββ Cargo.toml # Rust dependencies
β βββ Cargo.lock # Rust lockfile
βββ tenant-service/ # Go tenant management service
β βββ go.mod # Go module definition
β βββ go.sum # Go dependencies checksum
β βββ cmd/ # Command line applications
β β βββ server/ # Main server application
β β βββ main.go # Server entrypoint
β βββ internal/ # Private application code
β β βββ api/ # API handlers and routes
β β βββ models/ # Data models
β β βββ services/ # Business logic
β βββ pkg/ # Public packages
β βββ tenant/ # Tenant management package
βββ terraform/ # Infrastructure as code
β βββ main.tf # Main Terraform configuration
β βββ variables.tf # Variable definitions
β βββ secrets/ # Environment-specific variables
β βββ template.tfvars # Template for environment variables
β βββ dev.tfvars # Development environment variables
β βββ prod.tfvars # Production environment variables
βββ k8s/ # Kubernetes manifests
β βββ base/ # Base configurations
β β βββ namespace.yaml # Namespace definition
β β βββ persistent-volumes.yaml # Persistent volume definitions
β βββ tenant-service/ # Tenant service configurations
β β βββ base/ # Base tenant service configs
β βββ nginx/ # Nginx configurations
β β βββ base/ # Base nginx configs
β βββ redis/ # Redis configurations
β β βββ base/ # Base redis configs
β βββ overlays/ # Environment-specific configurations
β βββ dev/ # Development environment
β βββ prod/ # Production environment
βββ scripts/ # Utility scripts
βββ all-in-one.sh # All-in-one management script
- Docker or Podman
- Kubernetes cluster (or Minikube for local development)
- Terraform
- kubectl
- kustomize (installed automatically by the management script)
This project includes a comprehensive all-in-one management script that handles all aspects of development, deployment, and management.
# Make the script executable
chmod +x scripts/all-in-one.sh
# Create a convenient symlink
ln -sf scripts/all-in-one.sh ./manage
# Run the interactive menu
./manage
The management script provides an interactive menu system with the following options:
-
Development Environment
- Deploy using Kustomize
- Deploy using Terraform + K8s
- Show Kubernetes resources
- Get pod logs
- Restart deployments
- Shell into a pod
- Check SSL certificates
- Clean up resources
-
Production Environment
- Same options as development (with confirmation prompts for safety)
-
Local Development
- Run application with Go or Podman
- Run Rust tenant service
- Deploy locally using docker-compose
-
Tools & Setup
- Install required tools
- Set up development environment
- Set up production environment
You can also use the script directly with commands:
# General syntax
./manage <command> [options]
Common commands:
# Install required tools
sudo ./manage install
# Set up development environment
./manage setup dev
# Deploy to development environment
./manage deploy dev
# Deploy to development with Kustomize
./manage kustomize dev
# Run local application (Go or Podman)
./manage run-local
# Run Rust tenant service
./manage run-rust
# Deploy locally with docker-compose
./manage deploy-local
# Check status of deployments
./manage status dev
# View logs from pods
./manage logs dev
# Open shell in a pod
./manage shell dev
# Check SSL certificates
./manage ssl-status dev
# Restart deployments
./manage restart dev
# Clean up resources
./manage cleanup dev
The Kubernetes configurations follow a Kustomize-based structure:
- Base: Contains shared resources (namespace, persistent volumes)
- Component Directories: Component-specific configurations:
tenant-service
: Main backend servicenginx
: Frontend proxy with SSL terminationredis
: Caching layer
- Overlays: Environment-specific configurations
dev
: Development environment settingsprod
: Production environment settings with higher replica counts
For local development, you can use:
# Run the Go application directly
./manage run-local
# Select option 1 when prompted
# Run with docker-compose/podman-compose
./manage run-local
# Select option 2 when prompted
# Run the Rust tenant service
./manage run-rust
# Deploy locally with all services
./manage deploy-local
This project uses a multi-layered approach to secret management:
- Development: Environment variables or ConfigMaps
- Kubernetes: Kubernetes Secrets mounted as files
- Terraform: Terraform variables for infrastructure secrets
- Create a new directory in
k8s/
for your component - Add base manifests in a
base/
subdirectory - Update overlays to include your component
- Deploy using
./manage kustomize dev
- Create a new directory in
k8s/overlays/
for your environment - Copy files from an existing environment as templates
- Set up Terraform variables:
./manage setup <new-env>
- Deploy to the new environment:
./manage deploy <new-env>
The management script includes built-in troubleshooting capabilities:
# Check deployment status
./manage status dev
# View pod logs
./manage logs dev
# Shell into a pod for debugging
./manage shell dev
Common issues and solutions:
- Connection to database fails: Check the database credentials in your ConfigMap or environment variables
- Kubernetes pods not starting: Check pod status and logs with
./manage status dev
and./manage logs dev
- Terraform errors: Ensure your
.tfvars
file has all required variables
For more detailed troubleshooting, check the README files in each component directory:
k8s/README.md
: Overview of Kubernetes structurek8s/tenant-service/README.md
: Tenant service detailsk8s/nginx/README.md
: Nginx proxy detailsk8s/redis/README.md
: Redis cache detailsscripts/README-all-in-one.md
: Detailed usage of the management script