BugX CLI is a command-line tool for managing Kubernetes service tunnels through port-forwarding. It provides a simple and intuitive interface to create, manage, and monitor port-forward connections to Kubernetes services.
- π Port Forwarding: Create port-forward tunnels to Kubernetes services
- π Service Discovery: List and explore Kubernetes services
- π Connection Management: Manage multiple active connections
- π Background Mode: Run port-forwards in the background as daemon processes
- πΎ Persistent Storage: Track connections across sessions
- π― Smart Defaults: Automatic port selection and pod discovery
- Go 1.16 or later
- Kubernetes cluster access (kubeconfig)
git clone <repository-url>
cd bugxcli
go build -o bugx ./cmd/bugxgo install ./cmd/bugxBugX CLI stores configuration in ~/.bugx/ directory:
config.json: General configuration (cluster name)connections.json: Active port-forward connections
KUBECONFIG: Path to kubeconfig file (default:~/.kube/config)
List all services in a namespace:
bugx services list --namespace <namespace>Or use the default namespace:
bugx services listOptions:
--kubeconfig, -k: Path to kubeconfig file--namespace, -n: Namespace to list services from (default:default)
Create a port-forward tunnel to a Kubernetes service:
bugx connect <service-name> [flags]Basic Example:
bugx connect mysql-service --namespace productionAdvanced Example:
bugx connect mysql-service \
--namespace production \
--localport 3307 \
--remoteport 3306 \
--kubeconfig ~/.kube/configFlags:
--kubeconfig, -k: Path to kubeconfig file (defaults toKUBECONFIGenv var or~/.kube/config)--namespace, -n: Namespace of the service (default:default)--localport, -l: Local port to forward to (defaults to remote port + 1)--remoteport, -r: Remote port on the pod (defaults to first service port)--background, -b: Run port-forward in background (default:true)
How it works:
- Finds the service in the specified namespace
- Discovers pods behind the service using service selectors
- Selects the first available pod
- Creates a port-forward connection
- Runs in background by default (or foreground if
--background=false)
View all active port-forward connections:
bugx connect listThis command shows:
- Service name and namespace
- Pod name
- Local and remote ports
- Process ID (PID)
- Connection status
Stop an active port-forward connection:
bugx disconnect <service-name> [flags]Example:
bugx disconnect mysql-service --namespace productionFlags:
--namespace, -n: Namespace of the service (default:default)
The command will:
- Find the connection by service name and namespace
- Terminate the background process (SIGTERM, then SIGKILL if needed)
- Remove the connection from the active connections list
# 1. List available services
bugx services list --namespace production
# 2. Connect to a database service
bugx connect mysql-db --namespace production --localport 3307
# 3. Check active connections
bugx connect list
# 4. Disconnect when done
bugx disconnect mysql-db --namespace productionTo run a port-forward in the foreground (useful for debugging):
bugx connect redis-service --namespace default --background=falsePress Ctrl+C to stop the connection.
# Forward local port 5432 to remote port 5432
bugx connect postgres-service \
--namespace production \
--localport 5432 \
--remoteport 5432bugxcli/
βββ cmd/
β βββ bugx/
β βββ cmd/
β β βββ root.go # Root command and CLI setup
β β βββ connect.go # Port-forward connection management
β β βββ disconnect.go # Disconnect connections
β β βββ services.go # Service listing
β β βββ daemon.go # Daemon command (internal)
β β βββ connection.go # Connection state management
β β βββ kubeconfig.go # Kubeconfig path resolution
β β βββ portforward_daemon.go # Background port-forward implementation
β βββ config/
β β βββ config.go # Configuration management
β βββ main.go # Entry point
-
Configuration Management (
config/config.go):- Cluster name persistence
- Secure file permissions
-
Connection Management (
cmd/connection.go):- Track active port-forward connections
- Process ID tracking
- Connection state persistence
- Thread-safe operations
-
Port Forwarding (
cmd/connect.go,cmd/portforward_daemon.go):- Kubernetes client integration
- Service and pod discovery
- Background daemon process management
- Foreground port-forward support
- Cobra: CLI framework
- Kubernetes Client-Go: Kubernetes API client
- Configuration files use secure permissions (0600)
- Background processes run with proper signal handling
If you see "connection already exists", use bugx connect list to see active connections and disconnect the existing one first.
If background port-forwards fail to start, try:
- Running in foreground mode first to see error messages:
--background=false - Check kubeconfig permissions and validity
- Verify service and pod exist in the namespace
Ensure:
KUBECONFIGenvironment variable is set, or~/.kube/configexists, or- Use
--kubeconfigflag to specify path
If the local port is already in use:
- Use
--localportto specify a different port - Check existing connections with
bugx connect list - Disconnect conflicting connections
Contributions are welcome! Please ensure:
- Code follows Go best practices
- Tests are included for new features
- Documentation is updated
For issues and questions, please open an issue on the project repository.