Bulk port forwarding Kubernetes services for local development.
Kubernetes port forwarding for local development.
Read Kubernetes Port Forwarding for Local Development for background and a detailed guide to kubefwd. Follow Craig Johnston on Twitter for project updates.
kubefwd is a command line utility built to port forward multiple services within one or more namespaces on one or more Kubernetes clusters. kubefwd uses the same port exposed by the service and forwards it from a loopback IP address on your local workstation. kubefwd temporally adds domain entries to your
/etc/hostsfile with the service names it forwards.
When working on our local workstation, my team and I often build applications that access services through their service names and ports within a Kubernetes namespace. kubefwd allows us to develop locally with services available as they would be in the cluster.
Tested directly on macOS and Linux based docker containers.
kubefwd assumes you have kubectl installed and configured with access to a Kubernetes cluster. kubefwd uses the kubectl current context. The kubectl configuration is not used. However, its configuration is needed to access a Kubernetes cluster.
Ensure you have a context by running:
bash kubectl config current-context
If you are running MacOS and use homebrew you can install kubefwd directly from the txn2 tap:
brew install txn2/tap/kubefwd
To upgrade:
bash brew upgrade kubefwd
scoop install kubefwd
To upgrade:
batch scoop update kubefwd
Forward all services from the namespace the-project to a Docker container named the-project:
docker run -it --rm --privileged --name the-project \ -v "$(echo $HOME)/.kube/":/root/.kube/ \ txn2/kubefwd services -n the-project
Execute a curl call to an Elasticsearch service in your Kubernetes cluster:
docker exec the-project curl -s elasticsearch:9200
Check out the releases section on Github for alternative binaries.
Fork kubefwd and build a custom version. We welcome any useful pull requests.
Forward all services for the namespace
the-project. Kubefwd finds the first Pod associated with each Kubernetes service found in the Namespace and port forwards it based on the Service spec to a local IP address and port. A domain name is added to your /etc/hosts file pointing to the local IP.
Forwarding of headlesss Service is currently supported, Kubefwd forward all Pods for headless service; At the same time, the namespace-level service monitoring is supported. When a new service is created or the old service is deleted under the namespace, kubefwd can automatically start/end forwarding; Supports Pod-level forwarding monitoring. When the forwarded Pod is deleted (such as updating the deployment, etc.), the forwarding of the service to which the pod belongs is automatically restarted;
sudo kubefwd svc -n the-project
Forward all svc for the namespace
the-projectwhere labeled
system: wx:
sudo kubefwd svc -l system=wx -n the-project
Forward more than one service using the
inclause:
bash sudo kubefwd svc -l "app in (app1, app2)"
$ kubefwd svc --helpINFO[20:48:38] _ _ __ _ INFO[20:48:38] | | _ _| | ___ / | ____| | INFO[20:48:38] | |/ / | | | '_ \ / _ \ |_\ \ /\ / / _ | INFO[20:48:38] |
Development
Build and Run
Local
go run ./cmd/kubefwd/kubefwd.goBuild Release
Build test release:
bash goreleaser --skip-publish --rm-dist --skip-validateBuild and release:
bash GITHUB_TOKEN=$GITHUB_TOKEN goreleaser --rm-distLicense
Apache License 2.0
Similar projects, products, alternatives and complementary utilities
Open source utility by Craig Johnston, imti blog and sponsored by Deasil Works, Inc.
Please check out my book Advanced Platform Development with Kubernetes: Enabling Data Management, the Internet of Things, Blockchain, and Machine Learning.
Source code from the book Advanced Platform Development with Kubernetes: Enabling Data Management, the Internet of Things, Blockchain, and Machine Learning by Craig Johnston (@cjimti) ISBN 978-1-4842-5610-7 Apress; 1st ed. edition (September, 2020)
Read my blog post Advanced Platform Development with Kubernetes for more info and background on the book.
Follow me on Twitter: @cjimti (Craig Johnston)