# Kubefwd — Bulk Port Forwarding for Kubernetes Services > A command-line tool that bulk-forwards Kubernetes services to your local machine, mapping service DNS names to localhost. Kubefwd lets developers access remote cluster services as if they were running locally. ## Install Save as a script file and run: # Kubefwd — Bulk Port Forwarding for Kubernetes Services ## Quick Use ```bash # Install brew install txn2/tap/kubefwd # Forward all services in a namespace sudo kubefwd svc -n my-namespace # Now access services by name: curl http://my-api:8080 ``` ## Introduction Kubefwd eliminates the tedious process of setting up individual kubectl port-forward commands for each service. It forwards all services in a namespace at once, adds entries to /etc/hosts so you can use real service names, and keeps connections alive — making local development against a remote cluster seamless. ## What Kubefwd Does - Bulk-forwards all services in one or more Kubernetes namespaces simultaneously - Maps Kubernetes service DNS names to local loopback addresses via /etc/hosts entries - Maintains persistent connections with automatic reconnection on pod restarts - Supports label selectors to forward only specific services - Forwards multiple ports per service matching the Kubernetes service port definitions ## Architecture Overview Kubefwd reads service definitions from the Kubernetes API, resolves backing pods, and establishes port-forward tunnels to each. It writes entries to /etc/hosts mapping each service name to a loopback address (127.1.27.x range) and binds local listeners on the correct ports. When pods restart, Kubefwd detects the change and re-establishes the tunnel transparently. ## Self-Hosting & Configuration - Install via Homebrew, Scoop, or download pre-built binaries from GitHub releases - Run with sudo (required for /etc/hosts modification) specifying target namespaces - Use -l flag with label selectors to forward only services matching specific labels - Configure multiple namespace forwarding with repeated -n flags - Set KUBECONFIG environment variable or use --kubeconfig to target specific clusters ## Key Features - Zero-config service discovery uses actual Kubernetes service names for DNS - Supports TCP services on any port with multi-port service forwarding - Automatic reconnection handles pod rescheduling without manual intervention - Namespace isolation prevents port conflicts across different environments - MCP server support enables AI agents to interact with forwarded services ## Comparison with Similar Tools - **kubectl port-forward** — single service at a time; Kubefwd does bulk forwarding with DNS - **Telepresence** — full traffic intercept with two-way networking; Kubefwd is lighter, read-only forwarding - **Skaffold dev** — rebuilds and deploys on code changes; Kubefwd forwards existing services only - **ktunnel** — exposes local services to the cluster (reverse); Kubefwd forwards cluster to local - **stern** — log tailing tool; complementary to Kubefwd for debugging cluster services ## FAQ **Q: Why does Kubefwd need sudo?** A: It modifies /etc/hosts to map service names to local IPs. Without this, you would need to use IP addresses. **Q: Can I forward services from multiple namespaces?** A: Yes. Pass multiple -n flags: kubefwd svc -n staging -n shared-services. **Q: Does it work with headless services?** A: Kubefwd works with ClusterIP services. Headless services require targeting individual pods. **Q: What happens when a pod restarts?** A: Kubefwd detects the change and automatically re-establishes the port-forward to the new pod. ## Sources - https://github.com/txn2/kubefwd - https://kubefwd.com --- Source: https://tokrepo.com/en/workflows/9d8da470-39d2-11f1-9bc6-00163e2b0d79 Author: Script Depot