• Stars
    star
    3,676
  • Rank 12,020 (Top 0.3 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created over 6 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Bulk port forwarding Kubernetes services for local development.

English|ไธญๆ–‡

Kubernetes port forwarding for local development.

NOTE: Accepting pull requests for bug fixes, tests, and documentation only.

kubefwd - kubernetes bulk port forwarding

Build Status GitHub license Go Report Card GitHub release

kubefwd (Kube Forward)

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/hosts file 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.

kubefwd - Kubernetes port forward

kubefwd - Kubernetes Port Forward Diagram

OS

Tested directly on macOS and Linux based docker containers.

MacOs Install / Update

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:

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:

brew upgrade kubefwd

Windows Install / Update

scoop install kubefwd

To upgrade:

scoop update kubefwd

Docker

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

Alternative Installs (tar.gz, RPM, deb)

Check out the releases section on Github for alternative binaries.

Contribute

Fork kubefwd and build a custom version. Accepting pull requests for bug fixes, tests, stability and compatibility enhancements, and documentation only.

Usage

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.

Update

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-project where labeled system: wx:

sudo kubefwd svc -l system=wx -n the-project

Forward a single service named my-service in the namespace the-project:

sudo kubefwd svc -n the-project -f metadata.name=my-service

Forward more than one service using the in clause:

sudo kubefwd svc -l "app in (app1, app2)"

Help

$ kubefwd svc --help

INFO[00:00:48]  _          _           __             _     
INFO[00:00:48] | | ___   _| |__   ___ / _|_      ____| |    
INFO[00:00:48] | |/ / | | | '_ \ / _ \ |_\ \ /\ / / _  |    
INFO[00:00:48] |   <| |_| | |_) |  __/  _|\ V  V / (_| |    
INFO[00:00:48] |_|\_\\__,_|_.__/ \___|_|   \_/\_/ \__,_|    
INFO[00:00:48]                                              
INFO[00:00:48] Version 0.0.0                                
INFO[00:00:48] https://github.com/txn2/kubefwd              
INFO[00:00:48]                                              
Forward multiple Kubernetes services from one or more namespaces. Filter services with selector.

Usage:
  kubefwd services [flags]

Aliases:
  services, svcs, svc

Examples:
  kubefwd svc -n the-project
  kubefwd svc -n the-project -l app=wx,component=api
  kubefwd svc -n default -l "app in (ws, api)"
  kubefwd svc -n default -n the-project
  kubefwd svc -n default -d internal.example.com
  kubefwd svc -n the-project -x prod-cluster
  kubefwd svc -n the-project -m 80:8080 -m 443:1443
  kubefwd svc -n the-project -z path/to/conf.yml
  kubefwd svc -n the-project -r svc.ns:127.3.3.1
  kubefwd svc --all-namespaces

Flags:
  -A, --all-namespaces          Enable --all-namespaces option like kubectl.
  -x, --context strings         specify a context to override the current context
  -d, --domain string           Append a pseudo domain name to generated host names.
  -f, --field-selector string   Field selector to filter on; supports '=', '==', and '!=' (e.g. -f metadata.name=service-name).
  -z, --fwd-conf string         Define an IP reservation configuration
  -h, --help                    help for services
  -c, --kubeconfig string       absolute path to a kubectl config file
  -m, --mapping strings         Specify a port mapping. Specify multiple mapping by duplicating this argument.
  -n, --namespace strings       Specify a namespace. Specify multiple namespaces by duplicating this argument.
  -r, --reserve strings         Specify an IP reservation. Specify multiple reservations by duplicating this argument.
  -l, --selector string         Selector (label query) to filter on; supports '=', '==', and '!=' (e.g. -l key1=value1,key2=value2).
  -v, --verbose                 Verbose output.

License

Apache License 2.0

Sponsor

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.

Book Cover - 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)

Please Help the Children of Ukraine

UNICEF is on the ground helping Ukraine's children, please donate to https://www.unicefusa.org/ <- "like" this project by donating.

More Repositories

1

txeh

Go library and CLI utility for /etc/hosts management.
Go
307
star
2

txpdf

HTML to PDF microservice
XSLT
91
star
3

n2proxy

Contraband filtering reverse proxy for plain http and SSL.
Go
32
star
4

asws

Another static web server, plus JSON REST API for exposing specified directory listings. Useful for download pages or listings asset for web applications.
Go
22
star
5

irsync

rsync on interval, via command line binary or docker container. Server and IOT builds for pull or push based device content management.
Go
21
star
6

rxtx

Queue based data collector, transmitter with store-and-forward. Useful for online/offline data collection, back pressure buffering or general queuing. REST / HTTP post.
Go
18
star
7

p3y

A single binary reverse proxy written in go. It was developed for use in Kubernetes, to wrap services like Prometheus with simple BasicAuth and TLS encryption.
Go
17
star
8

datalab

Custom JupyterLab container for local-workstations and in-cluster Kubernetes Data Science, Machine Learning and IoT.
Dockerfile
12
star
9

provision

WIP: User and Account micro-platform.
Go
8
star
10

n2pdf

Alpine based container providing a stable wrapper for wkhtmltopdf
8
star
11

rtbeat

Rtbeat processes HTTP POST data from rxtx and publishes events into elasticsearch, logstash, kafka, redis or directly to log files.
Go
8
star
12

txtoken

txToken creates an HS256 JWT token from JSON retrieved from a remote endpoint resulting from a proxied JSON request body.
Go
8
star
13

amp

Kubernetes Dynamic Admission Control mutating Webhook proxy for Pods.
Go
7
star
14

mxt

Endpoint proxy for data transformation.
Go
6
star
15

docker-kubectl

Kubectl installed in an alpine based image from docker. Used for container building and k8s deployments in CI/CD.
Dockerfile
6
star
16

dmk

Declarative data migration.
Go
5
star
17

homebrew-tap

Homebrew Tap
Ruby
5
star
18

es

WIP: TXN2 Elasticsearch utilities
Go
5
star
19

xn2

pull, synchronize and package data on interval.
Go
5
star
20

jwtpxy

jwtpxy simplifies API security by pre-validating and parsing JWT web tokens into HTTP headers easily read by backend services.
Go
4
star
21

n2bot

Go
3
star
22

pvci

WIP: PVC Injector
Go
3
star
23

query

TNX2 Elasticsearch query system
Go
3
star
24

txagent

Docker based iot container orchestration for arm based devices (Raspberry Pi / Orange Pi / Tinkerboard) or traditional servers.
Go
3
star
25

service

Go
2
star
26

gpu-lab

GPU enabled JupyterLab containers.
Dockerfile
2
star
27

tm

WIP: TXN2 types model API
Go
2
star
28

amp-wh-example

Admission Mutation Proxy (txn2/amp) implementation example project.
Go
2
star
29

ok

OK message served by http, written in Go as a Kubernetes/Minikube tutorial.
Go
2
star
30

ack

TXN2 common API acknowledgement Go lib.
Go
2
star
31

micro

WIP: TXN2 micro server (gin-gonic wrapper)
Go
2
star
32

kwatch

Kafka utility container for Kubernetes
Go
2
star
33

kagent

Makefile
1
star
34

hugo-builder

Small container with Hugo, for building static sites.
Dockerfile
1
star
35

n2cas

Go
1
star
36

userpatches

Armbian userpatches for txn2
Shell
1
star
37

kdash

JavaScript
1
star
38

grape

WIP: TXN2 GRAfana Proxy for Elasticsearch data source.
Go
1
star
39

qlrx

WIP: TXN2 QL tcp receiver
Go
1
star
40

txwt

Makefile
1
star
41

curl

Apline curl container
Makefile
1
star
42

fxtx

WIP: TXN2 Fake transmission
Go
1
star
43

phc

Performance Hobby Cluster
1
star
44

www

Site
CSS
1
star
45

easy-novnc-container

Container for easy-novnc
Dockerfile
1
star
46

token

WIP: TXN2 JWT user token
Go
1
star
47

n2tok

JWT Token abstraction for TXN2 based services.
Go
1
star