kubefwd
CLAUDE.md4.2k starsChanged 11 months agoApache-2.0View on GitHub
kubefwd is a popular command-line utility for bulk Kubernetes port forwarding, featured in "essential k8s developer tools" lists. It forwards multiple services from one or more namespaces, adding corresponding entries to /etc/hosts for local development. Key Differentiator from kubectl port-forward: Each service gets its own unique loopback IP address (127.x.x.x), allowing multiple services to use the same port simultaneously (e.g., multiple databases on port 3306, or multiple web services on port 80). This mirrors how services work in the cluster,…
Trending
Quiet since June.about the whole repository
Who's talking about txn2/kubefwd
- NixOS/nixpkgs“kubefwd: /etc/hosts is not writeable”GitHub · Jun 27, 2025 · 4 reactions
- @josedevezas.com“This is probably obvious for everyone using #Kubernetes out there, but, for those it's not, you can use …”Bluesky · Dec 17, 2024 · 4 likes
- NixOS/nixpkgs“Package request: kubefwd”GitHub · Jan 24, 2024 · 4 reactions
- NixOS/nixpkgs“kubefwd: init at 1.22.5”GitHub · Feb 16, 2024 · 2 reactions
- avelino/awesome-go“Add kubefwd to DevOps Tools”GitHub · Jan 8, 2026 · 1 reactions
The biggest 5 of 46 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 46
Talked about on GitHub, Hacker News and Bluesky (46 times).
On GitHub · 44
- Jun 27, 2025kubefwd: /etc/hosts is not writeable — NixOS/nixpkgs4 reactions
- Jan 24, 2024Package request: kubefwd — NixOS/nixpkgs4 reactions
- Feb 16, 2024kubefwd: init at 1.22.5 — NixOS/nixpkgs2 reactions · 2 comments
- Jan 8, 2026Add kubefwd to DevOps Tools — avelino/awesome-go1 reaction · 2 comments
- May 11, 2020Connecting to a Kubernetes Service when running the operator locally — operator-framework/operator-sdk1 reaction · 11 comments
39 more on GitHub
- Jun 20, 2026kubefwd: 1.25.15 -> 1.25.16 — NixOS/nixpkgs0 reactions
- Jun 20, 2026chore(deps): update kubefwd to v1.25.16 — uniget-org/tools0 reactions · 3 comments
- Jun 20, 2026kubefwd 1.25.16 — Homebrew/homebrew-core0 reactions · 1 comment
- Jun 20, 2026chore(deps): update dependency txn2/kubefwd to v1.25.16 — ponkio-o/dotfiles0 reactions
- May 30, 2026chore(deps): update kubefwd to v1.25.15 — uniget-org/tools0 reactions · 3 comments
- May 29, 2026kubefwd: 1.25.14 -> 1.25.15 — NixOS/nixpkgs0 reactions · 2 comments
- May 29, 2026chore(deps): update dependency txn2/kubefwd to v1.25.15 — ponkio-o/dotfiles0 reactions
- May 29, 2026kubefwd 1.25.15 — Homebrew/homebrew-core0 reactions · 1 comment
- Apr 24, 2026kubefwd: 1.25.13 -> 1.25.14 — NixOS/nixpkgs0 reactions
- Apr 22, 2026kubefwd 1.25.14 — Homebrew/homebrew-core0 reactions · 1 comment
- Apr 20, 2026kubefwd v1.25.13: SHA-256 mismatch on macOS arm64 (and likely all platforms) — formula references stale checksum — txn2/homebrew-tap0 reactions · 1 comment
- Mar 29, 2026kubefwd 1.25.13 — Homebrew/homebrew-core0 reactions · 1 comment
- Feb 10, 2026kubefwd 1.25.12 — Homebrew/homebrew-core0 reactions · 1 comment
- Feb 10, 2026kubefwd: 1.25.9 -> 1.25.13 — NixOS/nixpkgs0 reactions · 4 comments
- Feb 4, 2026kubefwd 1.25.10 — Homebrew/homebrew-core0 reactions · 1 comment
- Jan 8, 2026New package: txn2.kubefwd version 1.25.9 — microsoft/winget-pkgs0 reactions · 4 comments
- Jan 6, 2026Add kubefwd to Productivity Tools — wmariuss/awesome-devops0 reactions
- Jan 6, 2026Add kubefwd - Kubernetes bulk port forwarding with TUI — toolleeo/awesome-cli-apps-in-a-csv0 reactions
- Jan 4, 2026chore(deps): update dependency txn2/kubefwd to v1.25.8 — uniget-org/tools0 reactions · 3 comments
- Jan 4, 2026chore(deps): update dependency txn2/kubefwd to v1.25.8 — ponkio-o/dotfiles0 reactions
- Jan 4, 2026kubefwd: 1.22.5 -> 1.25.9 — NixOS/nixpkgs0 reactions · 13 comments
- Jan 4, 2026[BUG]: kubefwd: Autoupdate broken due to missing 'v' prefix in URL pattern — ScoopInstaller/Main0 reactions
- Jan 3, 2026[BUG]: kubefwd: Autoupdate broken due to missing 'v' prefix in URL pattern — ScoopInstaller/Main0 reactions · 1 comment
- Dec 30, 2025chore(deps): update dependency txn2/kubefwd to v1.25.2 — ponkio-o/dotfiles0 reactions
- Dec 29, 2025chore(deps): update dependency txn2/kubefwd to v1.25.0 — uniget-org/tools0 reactions · 3 comments
- Dec 29, 2025chore(deps): update dependency txn2/kubefwd to v1.25.0 — ponkio-o/dotfiles0 reactions
- Dec 28, 2025feat(txn2/kubefwd): cosign config — aquaproj/aqua-registry0 reactions · 1 comment
- Dec 28, 2025chore(deps): update dependency txn2/kubefwd to v1.24.1 — uniget-org/tools0 reactions · 3 comments
- Dec 28, 2025chore(deps): update dependency txn2/kubefwd to v1.24.1 — ponkio-o/dotfiles0 reactions
- Dec 27, 2025chore(deps): update dependency txn2/kubefwd to v1.24.0 — uniget-org/tools0 reactions · 3 comments
- Dec 27, 2025chore(deps): update dependency txn2/kubefwd to v1.24.0 — ponkio-o/dotfiles0 reactions
- Dec 20, 2025chore(deps): update dependency txn2/kubefwd to v1.25.12 — killo431/tools0 reactions
- Dec 19, 2025chore(deps): update dependency txn2/kubefwd to v1.25.16 — ebesson/dotfiles0 reactions
- Dec 19, 2025Update dependency txn2/kubefwd to v1.25.16 - abandoned — CrystalMethod/dotfiles0 reactions · 1 comment
- Dec 18, 2025enhancement: support list of hosts added with the tool kubefwd — productdevbook/port-killer0 reactions
- Oct 12, 2021Kubernetes Tools — HarshadRanganathan/harshadranganathan.github.io0 reactions · 2 comments
- Apr 14, 2021Add kubefwd (bulk port forwarding) — nicholasdille/homebrew-tap0 reactions
- Dec 7, 2020Add kubefwd — nicholasdille/packages0 reactions
- Jun 21, 2019lorri services: prior art link collection — target/lorri0 reactions · 10 comments
On Hacker News · 1
- Nov 19, 2018Kubefwd: CLI utility for port forwarding pods within a Kubernetes namespace1 point
On Bluesky · 1
- Dec 17, 2024This is probably obvious for everyone using #Kubernetes out there, but, for those it's not, you can use kubefwd to expose services and… — @josedevezas.com4 likes and reposts
In this repository2 other files it gives its agents.
- docs/llms-full.txtllms.txt
- docs/llms.txtllms.txt
The file
We split this CLAUDE.md into the rules it gives an agent
8 rules. About 0 are common, 4 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 61
All commits require explicit human approval: Do not run git commit unless the user explicitly asks you to commit.
- Very specific: line 219
Always run with sudo -E to preserve environment variables (KUBECONFIG).
- Distinctive: line 304
Test coverage has improved significantly:
- Distinctive: line 365
Add better error handling for watch events with non-pod objects
- Distinctive: line 366
Consider ignoring evicted pods earlier in the pipeline
- Very specific: line 399
Permission Errors: Always use sudo -E to preserve KUBECONFIG.
- Very specific: line 401
IP/Port Conflicts: Use IP reservations (-r or -z) to avoid conflicts.
- Very specific: line 405
Pod Watch Failures: Check RBAC permissions (list/get/watch pods, get services).
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
kubefwd is a popular command-line utility for bulk Kubernetes port forwarding, featured in "essential k8s developer tools" lists. It forwards multiple services from one or more namespaces, adding corresponding entries to /etc/hosts for local development.
Key Differentiator from kubectl port-forward: Each service gets its own unique loopback IP address (127.x.x.x), allowing multiple services to use the same port simultaneously (e.g., multiple databases on port 3306, or multiple web services on port 80). This mirrors how services work in the cluster, enabling truly cluster-like local development.
The tool automatically monitors service and pod lifecycle events, starting/stopping port forwards as services are created, deleted, or pods are rescheduled.
Integration and Usage Patterns
kubefwd is commonly integrated into development workflows:
- With Tilt: Blog posts document using kubefwd with Tilt for automated local development setups
- Development Environment Setup: Teams use kubefwd to mirror production-like service topologies locally
- Microservices Development: Allows developers to run one service locally while accessing dependencies in the cluster via service names
- Database Access: Popular for forwarding multiple databases (MySQL, PostgreSQL, MongoDB) on their native ports without port conflicts
The typical workflow: sudo -E kubefwd svc -n <namespace> --tui runs in a dedicated terminal while developers work in their IDE, accessing cluster services as if running in-cluster.
TUI (Terminal User Interface)
kubefwd includes an interactive TUI built with Bubble Tea, enabled with --tui:
sudo -E kubefwd svc -n default --tuiTUI Features
- Real-time service monitoring: See all forwarded services with connection status
- Traffic metrics: Bytes in/out with sparkline graphs
- Pod log streaming: View container logs directly in the TUI
- HTTP activity detection: Monitor HTTP requests/responses flowing through forwards
- Auto-reconnect: Enabled by default in TUI mode, with exponential backoff (1s → 5min max)
- Keyboard-driven: Full keyboard navigation (j/k, Enter, Tab, /, ?, q)
TUI Architecture
The TUI follows the Model-View-Update (MVU) pattern:
- Event Bus (
pkg/fwdtui/events): Decoupled pub/sub communication between components - State Store (
pkg/fwdtui/state): Centralized, thread-safe state management for all forwards - Metrics Registry (
pkg/fwdtui/metrics): Traffic counters with atomic operations - Components (
pkg/fwdtui/components): UI models for services list, logs, detail view
TUI Keyboard Shortcuts
j/kor arrows: NavigateEnter: Open detail viewTab: Switch panels/tabs/: Filter servicesr: Reconnect errored servicesb: Toggle bandwidth columns?: Help overlayq: Quit
Git Policy
All commits require explicit human approval. Do not run git commit unless the user explicitly asks you to commit. Always show the diff or summarize changes and wait for approval first.
Build and Development Commands
Building
# Build the project (uses goreleaser)
go build -o kubefwd ./cmd/kubefwd/kubefwd.go
# Build with version information
go build -ldflags "-X main.Version=dev" -o kubefwd ./cmd/kubefwd/kubefwd.goTesting
# Run all tests
go test ./...
# Run tests for a specific package
go test ./pkg/fwdport
# Run tests with verbose output
go test -v ./pkg/fwdportRunning Locally
# Requires root/sudo for network interface management and /etc/hosts modification
sudo ./kubefwd svc -n <namespace>
# Use -E flag to preserve environment (especially KUBECONFIG)
sudo -E ./kubefwd svc -n <namespace>
# With interactive TUI (recommended for development)
sudo -E ./kubefwd svc -n <namespace> --tuiDependencies
# Download dependencies
go mod download
# Update dependencies
go mod tidyDebugging and Development
# Enable verbose logging
sudo -E ./kubefwd svc -n <namespace> -v
# Test with a single service using field selector
sudo -E ./kubefwd svc -n <namespace> -f metadata.name=<service-name>
# Test with label selector
sudo -E ./kubefwd svc -n <namespace> -l app=myapp
# Use IP reservation config for reproducible testing
sudo -E ./kubefwd svc -n <namespace> -z example.fwdconf.ymlThe verbose flag (-v) enables debug-level logging (logrus.DebugLevel), which shows:
- Service registry operations
- Pod sync events
- IP allocation details
- Port forwarding lifecycle events
Demo Environment
A comprehensive demo manifest is available for testing:
# Deploy 60 services across 2 namespaces
kubectl apply -f test/manifests/demo-microservices.yaml
# Forward all demo services with TUI
sudo -E ./kubefwd svc -n kft1,kft2 --tui
# Cleanup
kubectl delete -f test/manifests/demo-microservices.yamlArchitecture
Core Components Flow
- Entry Point (
cmd/kubefwd/kubefwd.go): CLI entry, delegates to services command - Services Command (
cmd/kubefwd/services/services.go): Main orchestration logic- Validates cluster connectivity and RBAC permissions
- Creates Kubernetes informers to watch Service events (Add/Delete/Update)
- Spawns namespace watchers for each namespace×context combination
- Service Registry (
pkg/fwdsvcregistry): Central registry of all forwarded services- Thread-safe map of active ServiceFWD instances
- Handles lifecycle (add, remove, shutdown all)
- Service Forwarding (
pkg/fwdservice): Per-service forwarding logic- Queries pods backing each service
- Manages pod selection (single pod for normal services, all pods for headless)
- Debounces pod sync operations to avoid hammering k8s API
- Maintains map of active port forwards per pod
- Port Forwarding (
pkg/fwdport): Individual pod port forwarding- Creates SPDY connection to k8s API server
- Manages port forward lifecycle with watch for pod deletion
- Updates
/etc/hostsfile with service hostnames
- Network/IP Management (
pkg/fwdnet,pkg/fwdIp): Loopback interface management- Allocates unique 127.x.x.x IPs for each service
- Manages IP aliases on loopback interface (macOS: lo0, Linux: lo)
- Supports IP reservation via config file or CLI flags
Key Architectural Patterns
Event-Driven Architecture: Uses Kubernetes informers to react to service/pod lifecycle events in real-time.
Headless vs Normal Services:
- Normal services forward the first available pod using the service name
- Headless services (ClusterIP: None) forward all pods, with first pod as service name and rest as pod-name.service-name
Debouncing: Uses 5-second debouncer for pod sync operations to handle rapid pod changes (e.g., rolling deployments) without excessive k8s API calls.
Thread Safety: Extensive use of mutexes for:
- Per-namespace IP allocation (
NamespaceIPLock) - Service registry access
- Hosts file modifications
Shutdown Orchestration: Clean shutdown cascade:
- User signal → stopListenCh
- Namespace watchers stop
- Service registry shutdown
- Individual pod port forwards stop
- Hosts file cleanup and network alias removal
Package Responsibilities
fwdservice: Service-level forwarding orchestration and pod managementfwdport: Individual pod port forwarding via k8s APIfwdsvcregistry: Global service registry and lifecycle managementfwdnet: Network interface management (IP aliasing)fwdIp: IP allocation logic and reservation handlingfwdhost: Hosts file backup managementfwdcfg: Kubernetes client configurationfwdpub: Publisher interface for outputfwdtui: Terminal User Interface (Bubble Tea)fwdtui/components: UI view models (services list, logs, detail, help, status bar)fwdtui/events: Event bus with panic recovery for decoupled pub/subfwdtui/state: Thread-safe state store with RWMutex protectionfwdtui/metrics: Traffic metrics with atomic counters and rate calculationfwdtui/portforward: Port forward wrapper that emits metrics events
utils: Root permission checks (OS-specific)
Important Implementation Details
Root Permissions and Security
kubefwd requires superuser privileges for:
- Adding IP aliases to loopback interface
- Binding to low-numbered ports
- Modifying
/etc/hosts
Always run with sudo -E to preserve environment variables (KUBECONFIG).
Security Considerations: kubefwd is considered a "powerful but potentially dangerous tool" because it:
- Modifies system-level network configuration
- Changes
/etc/hostswhich affects DNS resolution system-wide - Requires root access which can impact system stability if misused
- Opens network connections to cluster services
The tool backs up the original hosts file to ~/hosts.original before making modifications, but improper shutdown can leave the system in an inconsistent state.
Hostname Generation
Hostnames follow pattern based on cluster and namespace indices:
- Namespace 0, Cluster 0:
service-name - Namespace >0:
service-name.namespace - Cluster >0:
service-name.contextorservice-name.namespace.context
For headless services, pods get: pod-name.service-name[.namespace][.context]
IP Allocation
Base IP is 127.1.x.x with incremental allocation. Can be customized via:
--fwd-confYAML config file (seeexample.fwdconf.yml)--reserveCLI flag for individual reservations
Port Mapping
Supports port remapping with -m flag (e.g., -m 80:8080 maps service port 80 to local 8080).
UDP Limitation
UDP port forwarding is not supported (Kubernetes API limitation: kubernetes/kubernetes#47862).
Code Organization
cmd/kubefwd/ # CLI entry point
kubefwd.go # Main entry, root command
services/
services.go # Services subcommand, namespace watchers
pkg/
fwdservice/ # Service forwarding logic
fwdport/ # Pod port forwarding
fwdsvcregistry/ # Service registry
fwdnet/ # Network interface management
fwdIp/ # IP allocation
fwdhost/ # Hosts file operations
fwdcfg/ # K8s config
fwdpub/ # Publisher
fwdtui/ # Terminal User Interface
components/ # UI models (services, logs, detail, help)
events/ # Event bus for decoupled communication
state/ # Centralized state store
metrics/ # Traffic metrics with atomic counters
portforward/ # Port forward wrapper with metrics
utils/ # Utilities (root check)
test/
integration/ # Integration tests (require KIND cluster)
manifests/ # Test Kubernetes manifests
scripts/ # Test setup/teardown scriptsContribution Policy
Public Contributions: The project welcomes pull requests from the community for:
- Bug fixes
- Tests
- Documentation
- Stability and compatibility enhancements
Feature Development: New features are developed by select contributors only. Public feature PRs are discouraged due to past experience with contributions that introduced drastic codebase changes, were difficult to review and test, and added significant technical debt. This policy is documented in the README.
Internal Development: Maintainers and trusted contributors are welcome to develop new features. If you're working on this codebase with direct access, feature development is encouraged.
Release Process
Uses GoReleaser (.goreleaser.yml):
- Builds for Linux, macOS, Windows (multiple architectures)
- Creates Docker images (Alpine and Ubuntu variants)
- Publishes to GitHub releases
- Updates Homebrew tap (txn2/homebrew-tap)
- Generates RPM, DEB, APK packages
The version is set via ldflags during build: -ldflags "-X main.Version={{.Version}}"
Testing
Unit Tests
Test coverage has improved significantly:
# Run all unit tests
go test ./...
# Run with coverage
go test -cover ./...
# Run specific package tests
go test -v ./pkg/fwdtui/events/... # Event bus tests (100% coverage)
go test -v ./pkg/fwdtui/components/... # UI component tests
go test -v ./pkg/fwdtui/state/... # State store tests
go test -v ./pkg/fwdport/... # Port forwarding testsIntegration Tests
Located in test/integration/, these require a KIND cluster:
# Setup KIND cluster
./test/scripts/setup-kind.sh
./test/scripts/deploy-test-services.sh test/manifests
# Run integration tests (requires sudo)
sudo -E go test -tags=integration -v ./test/integration/...
# Teardown
./test/scripts/teardown-kind.shIntegration tests cover: basic forwarding, headless services, auto-reconnect, multi-namespace, port mapping, and cleanup verification.
Areas for Additional Testing
- Hosts file race condition scenarios (Issue #74)
- Cleanup/restore logic for error conditions (Issue #5)
- Pod state filtering for evicted/completed pods (Issues #34, #114)
Areas for Improvement
Based on known issues, these areas would benefit from development:
Auto-Reconnect Enhancement
Auto-reconnect is now implemented (-a flag, enabled by default in TUI mode) with exponential backoff. However, edge cases may still exist:
- Very rapid pod cycling during rolling deployments
- Network partitions vs pod deletion detection
- Reconnection priority when multiple pods are available
Hosts File Synchronization (Issues #74, #79)
The HostFileWithLock mutex in pkg/fwdport may not be sufficient for all race conditions. Consider:
- Batching hosts file updates
- Implementing retry logic for failed updates
- Adding verification that all services are actually written
Graceful Shutdown (Issue #5)
Enhance the shutdown cascade to guarantee hosts file restoration even on signal interruption. Consider using defer more extensively or implementing a signal handler with guaranteed cleanup.
Pod State Filtering (Issues #34, #114)
The pod filtering in fwdservice.GetPodsForService() should be more defensive:
- Handle additional pod phases gracefully
- Add better error handling for watch events with non-pod objects
- Consider ignoring evicted pods earlier in the pipeline
Services Without Selectors (Issue #35)
Could potentially support endpoint-based services by querying Endpoints resources directly instead of relying on pod selectors.
Known Limitations and Active Issues
Based on community feedback and GitHub issues, developers should be aware of:
Architectural Limitations
Services Without Selectors (Issue #35): kubefwd does not support ClusterIP services without selectors (services backed by manually created Endpoints). The code assumes services have pod selectors and will skip services with empty selector strings.
Auto-Reconnect Available (Issue #21 resolved): Auto-reconnect is now implemented with the -a flag (enabled by default in TUI mode). When pods restart, kubefwd automatically re-establishes port forwards with exponential backoff (1s → 5min max).
UDP Protocol Not Supported: Kubernetes port-forwarding API limitation (kubernetes/kubernetes#47862).
Race Conditions and Edge Cases
Hosts File Race Condition (Issue #74): When forwarding multiple services simultaneously, especially on Windows with Docker Desktop, race conditions can occur during hosts file updates, leading to DNS resolution errors.
Hosts File Not Fully Restored (Issue #5): On certain error conditions or unclean shutdowns (Ctrl-C timing), the original /etc/hosts may not be fully restored. Always check ~/hosts.original backup.
Incomplete Hosts File Updates (Issue #79): Some services may be assigned IPs and be accessible but not appear in the hosts file. This appears related to timing in the hosts file update logic.
Pod State Handling
Evicted/Completed Pods (Issues #34, #114): Starting from v1.11.0, interface conversion errors occur with evicted pods or completed jobs. The code in pkg/fwdservice filters for PodPending and PodRunning states, but watch events for other states can cause errors.
Pod Status Assumptions: The code assumes pods are either Pending, Running, Succeeded, Failed, or Unknown. Edge cases with custom pod conditions may not be handled gracefully.
Common Issues and Troubleshooting
Permission Errors: Always use sudo -E to preserve KUBECONFIG.
IP/Port Conflicts: Use IP reservations (-r or -z) to avoid conflicts.
Stale /etc/hosts Entries: Original hosts file backed up to ~/hosts.original. Check this file if DNS resolution is broken after kubefwd exits.
Pod Watch Failures: Check RBAC permissions (list/get/watch pods, get services).
Connection Refused (localhost:8080): This usually means kubectl is not properly configured or KUBECONFIG was not preserved (missing -E flag with sudo).
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

