A lightweight load balancer and tunnel manager that accepts tunnel connections from a Kubernetes cluster and exposes cluster services to the public internet through the tunnel, similar to Nginx.
- HTTP and TCP load balancing
- WireGuard tunnel support
- Host-based and port-based routing
- RESTful API for tunnel management
- TLS support for secure connections
- Graceful shutdown handling
- Structured logging
- Go 1.19 or later
- WireGuard tools installed on the system
- (Optional) TLS certificates for HTTPS
go get github.com/quinnovator/easy-tunnel-lb-agent
Or clone the repository and build:
git clone https://github.com/quinnovator/easy-tunnel-lb-agent.git
cd easy-tunnel-lb-agent
go build -o easy-tunnel-lb-agent cmd/main.go
The agent can be configured using environment variables:
# API Server settings
export API_PORT=8080
export API_HOST=0.0.0.0
export API_BASE_PATH=/api
# Public Load Balancer settings
export PUBLIC_PORT=443
export PUBLIC_HOST=0.0.0.0
# TLS Configuration (optional)
export TLS_CERT_PATH=/path/to/cert.pem
export TLS_KEY_PATH=/path/to/key.pem
# Tunnel settings
export MAX_TUNNELS=100
# Logging
export LOG_LEVEL=info
./easy-tunnel-lb-agent --log-level=info
- Create a new tunnel:
curl -X POST http://localhost:8080/api/new-tunnel \
-H "Content-Type: application/json" \
-d '{
"tunnel_id": "my-service",
"hostname": "service.example.com",
"target_port": 8000,
"wireguard_public_key": "your-wireguard-public-key",
"metadata": {
"environment": "production",
"service": "web"
}
}'
- Remove a tunnel:
curl -X POST http://localhost:8080/api/remove-tunnel \
-H "Content-Type: application/json" \
-d '{
"tunnel_id": "my-service"
}'
- Get agent status:
curl http://localhost:8080/api/status
The agent consists of several components:
- API Server: Handles tunnel management requests
- Load Balancer: Routes incoming traffic to the appropriate tunnel
- Tunnel Manager: Manages tunnel lifecycle and configuration
- Router: Maintains routing tables for hostname and port-based routing
- WireGuard Manager: Handles WireGuard tunnel setup and configuration
easy-tunnel-lb-agent/
├── cmd/
│ └── main.go # Entry point
├── internal/
│ ├── api/ # API handlers and models
│ ├── loadbalancer/ # Load balancing logic
│ ├── tunnel/ # Tunnel management
│ ├── config/ # Configuration handling
│ └── utils/ # Utilities (logging, etc.)
└── README.md
# Build the binary
go build -o easy-tunnel-lb-agent cmd/main.go
# Run tests
go test ./...
# Run with debug logging
./easy-tunnel-lb-agent --log-level=debug
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
AGPL-v3