A fast, intelligent Kubernetes port forwarding tool with configuration-based resource management and automatic pod selection.
kubef is a command-line tool that simplifies Kubernetes port forwarding by providing:
- Configuration-driven forwarding - Define your forwarding rules in YAML configuration files
- Intelligent pod selection - Automatically discovers and forwards to healthy pods using label selectors, services, or deployments
- Load balancing - Distributes incoming connections across available pods
- Resource grouping - Organize resources into logical groups with aliases for easy management
- Real-time pod watching - Automatically adapts to pod changes using Kubernetes watch API
- High performance - Built in Rust with async/await for efficient connection handling
- Rust 2024 edition or later
- Access to a Kubernetes cluster with
kubectlconfigured
git clone https://github.com/marcocondrache/kubef && cd kubef
cargo install --path .This installs kubef to ~/.cargo/bin/. Make sure this directory is in your PATH.
Alternatively, build and copy manually:
cargo build --release
cp target/release/kubef /usr/local/bin/kubef uses YAML configuration files to define forwarding rules. By default, it looks for configuration in:
$KUBEF_CONFIG(if set)~/.config/kubef/config.yaml(XDG config directory)
groups:
<group_name>:
- alias: <resource_alias>
namespace: <namespace> # optional, defaults to "default"
selector:
type: <selector_type>
match: <selector_value>
ports:
remote: <pod_port> # target port on the pod
local: <local_port>- service - Select pods via Kubernetes service selector
- deployment - Select pods managed by a specific deployment
- label - Select pods using label key-value pairs
groups:
web:
- alias: frontend
namespace: production
selector:
type: service
match: frontend-service
ports:
remote: 8080
local: 3000
- alias: api
namespace: production
selector:
type: deployment
match: api-deployment
ports:
remote: 8000
local: 8000
development:
- alias: pdf
namespace: default
selector:
type: service
match: pdf
ports:
remote: 8080
local: 9000Forward to a specific resource by alias:
kubef pdfForward to a resource using the forward subcommand:
kubef forward --target pdfForward to all resources in a group:
kubef web- Configuration loading -
kubefloads your configuration file and parses the resource definitions - Resource resolution - Based on your target (alias or group), it identifies which resources to forward
- Pod discovery - For each resource, it uses the configured selector to find matching pods in the cluster
- Port binding - Creates local TCP listeners on the specified local ports
- Connection forwarding - When a connection arrives, it selects an available pod and establishes a port-forward tunnel
- Real-time updates - Continuously watches for pod changes and updates the available target pool
- Load balancing - Automatically distributes connections across healthy pods
- Fault tolerance - Handles pod restarts and failures gracefully
- Signal handling - Clean shutdown on Ctrl+C
- Structured Logging - Detailed logging with configurable levels via
KUBEF_LOGenvironment variable
groups:
services:
- alias: webapp
selector:
type: service
match: webapp-service
ports:
remote: 80
local: 8080kubef webapp
# Access your webapp at http://localhost:8080groups:
staging:
- alias: api
namespace: staging
selector:
type: deployment
match: api
ports:
remote: 8000
local: 8001
production:
- alias: api
namespace: production
selector:
type: deployment
match: api
ports:
remote: 8000
local: 8002# Forward staging API
kubef staging
# Or target specific environment
kubef api # Will forward all 'api' aliasesgroups:
monitoring:
- alias: prometheus
selector:
type: label
match:
- ["app", "prometheus"]
- ["component", "server"]
ports:
remote: 9090
local: 9090KUBEF_CONFIG_PATH- Custom path to configuration fileKUBEF_LOG- Set logging level (e.g.,KUBEF_LOG=debug kubef webapp)
- Rust 2024 edition
- Kubernetes cluster for testing
cargo buildcargo testsrc/main.rs- Application entry pointsrc/cli/- Command-line interface and argument parsingsrc/cnf/- Configuration management and parsingsrc/fwd/- Core port forwarding logic and pod watchingsrc/fwd/watcher.rs- Kubernetes pod watcher implementation
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
- "No resources found" - Check that your configuration file exists and contains the specified alias or group
- Connection refused - Ensure the target pods are running and the remote port is correct
- Permission denied - Verify your kubectl configuration and cluster access
Enable debug logging to see detailed information:
KUBEF_LOG=debug kubef webappThis will show configuration loading, pod discovery, and connection forwarding details.