kubetnl tunnels TCP connections from within a Kubernetes cluster to a cluster-external endpoint, e.g. to your local machine. (the perfect complement to kubectl port-forward)

kubetnl

kubetnl (kube tunnel) is a command line utility to tunnel TCP connections from within a Kubernetes to a cluster-external endpoint, e.g. to your local machine. You can think of it as doing the opposite of kubectl port-forward.

Demo

kubetnl-demo.gif

How does it work

When a new tunnel with kubetnl tunnel myservice 8080:8080 9090:9090 5.5.5.5:80:8888 is created, kubetnl will create a Service and a Pod with name "myservice" in your cluster. The pod will expose port 8080, 9090, 8888 and another random port for the tunnel. The service will target port 8080, 9090 and 8888 of the pod.

Once the pod is running, a connection to the pods exposed port for tunneling is established via pod portforwarding. Using the established connection to the pod, kubetnl opens a tunnel on the pod causing it to forward any incoming connections on port 8080, 9090 and 8888 to the kubetnl binary. From the kubetnl binary, the connections are then forwarded to their specified target endpoints.

Installation

Install using go install

If you have Go installed, you can simply run

go install github.com/fischor/kubetnl@latest

to install the latest version of kubetnl. You can replace latest with the version tag you want to install, e.g. v0.1.1.

Install by picking a relase

Go the the release section and pick the binary for your operation system and architecture and add it to your PATH.

Prerequisities

For kubetnl to work, you need to have privilidges the create services and pods and to do portforwarding on pods. Your cluster must also be able to pull the docker.io/fischor/kubetnl-server image.

Commands

kubetnl --help

$ kubetnl --help
kubetnl tunnels TCP connections from within a Kubernetes cluster to an external endpoint.

 Find more information and check out the souce code at: https://github.com/fischor/kubetnl

Basic commands
  tunnel      Setup a new tunnel
  cleanup     Delete all resources created by kubetnl

Other Commands:
  completion  generate the autocompletion script for the specified shell
  version     Print the kubetnl version

Usage:
  kubetnl [flags] [options]

Use "kubetnl <command> --help" for more information about a given command.
Use "kubetnl options" for a list of global command-line options (applies to all commands).

kubetnl tunnel --help

$ kubetnl tunnel --help
Setup a new tunnel.

 A tunnel forwards connections directed to a Kubernetes Service port within a cluster to an endpoint outside of the
cluster, e.g. to your local machine.

 Under the hood "kubetnl tunnel" creates a new service and pod that expose the specified ports. Any incoming connections
to an exposed port of the newly created service/pod will be tunneled to the endpoint specified for that port.

 "kubetnl tunnel" runs in the foreground. To stop press CTRL+C once. This will gracefully shutdown all active
connections and cleanup the created resources in the cluster before exiting.

Examples:
  # Tunnel to local port 8080 from myservice.<namespace>.svc.cluster.local:80.
  kubetnl tunnel myservice 8080:80

  # Tunnel to 10.10.10.10:3333 from myservice.<namespace>.svc.cluster.local:80.
  kubetnl tunnel myservice 10.10.10.10:3333:80

  # Tunnel to local port 8080 from myservice.<namespace>.svc.cluster.local:80 and to local port 9090 from myservice.<namespace>.svc.cluster.local:90.
  kubetnl tunnel myservice 8080:80 9090:90

  # Tunnel to local port 80 from myservice.<namespace>.svc.cluster.local:80 using version 0.1.0 of the kubetnl server
image.
  kubetnl tunnel --image docker.io/fischor/kubetnl-server:0.1.0 myservice 80:80

Options:
      --image='docker.io/fischor/kubetnl-server:0.1.0': The container image thats get deployed to serve a SSH server

Usage:
  kubetnl tunnel SERVICE_NAME TARGET_ADDR:SERVICE_PORT [...[TARGET_ADDR:SERVICE_PORT]] [flags] [options]

Use "kubetnl options" for a list of global command-line options (applies to all commands).

Alternatives

Since you are probably here in search for tools that allow you to forward traffic from within your cluster to the outside: here is a list of alternative tools that achieve similiar things as kubetnl and that might are what you are looking for:

Telepresence

Telepresence will forward traffic from within your cluster to your local machine and also forward traffic from your local machine to the cluster. Also any environment variables and volume mounts (not sure about that though) will be available on your local machine once "connected". If you are looking to setup a local development environment for microservice development, Telepresense is probably the right choice.

You still might choose kubetnl because:

With Telepresence, you need a to setup a Deployment manually before anything can be forwarded. Telepresence will then inject sidecar containers into the pods of that Deployment that are responsible for forwarding connections. kubetnl on the other hand creates a new service and pod for you, so there is no need to setup anything before the tunnel can be opened.

Telepresence will have to create a new namespace with a Traffic manager deployment (but setting it up and tearing it down is super easy) before anything can be forwarded. With kubectl there is no extra setup needed.

Telepresence forwards traffic from within the cluster only to your local machine, not to external endpoints (like kubetnl does).

VSCode Bridge to Kubernetes

VSCode Bridge to Kubernetes is quiet a similiar tool to Telepresense. It also allows you to forward traffic from your cluster to your local machine as well as the other way around making it a good environment for microservice development. For Brige to Kubernetes you need to have an existing pod (and service) set up. That pod gets replaced with a pod thats responsible for forwarding the traffic back and forth between the cluster and your local machine.

However, this only works as a VS Code extension and external endpoints are not supported.

Similar Resources

A kubectl plugin for easier query and operate k8s cluster.

A kubectl plugin for easier query and operate k8s cluster.

kube-query A kubectl plug-in that makes it easier to query and manipulate K8S clusters. (what is kubectl plug-in ?) Kube-query support some resource s

Jun 9, 2022

Kubectl plugin to ease sniffing on kubernetes pods using tcpdump and wireshark

Kubectl plugin to ease sniffing on kubernetes pods using tcpdump and wireshark

ksniff A kubectl plugin that utilize tcpdump and Wireshark to start a remote capture on any pod in your Kubernetes cluster. You get the full power of

Jan 4, 2023

kubectl plugin for signing Kubernetes manifest YAML files with sigstore

kubectl plugin for signing Kubernetes manifest YAML files with sigstore

k8s-manifest-sigstore kubectl plugin for signing Kubernetes manifest YAML files with sigstore ⚠️ Still under developement, not ready for production us

Nov 28, 2022

Kubectl plugin to run curl commands against kubernetes pods

kubectl-curl Kubectl plugin to run curl commands against kubernetes pods Motivation Sending http requests to kubernetes pods is unnecessarily complica

Dec 22, 2022

An operator to support Haschicorp Vault configuration workflows from within Kubernetes

Vault Config Operator This operator helps set up Vault Configurations. The main intent is to do so such that subsequently pods can consume the secrets

Sep 30, 2022

An operator to support Haschicorp Vault configuration workflows from within Kubernetes

An operator to support Haschicorp Vault configuration workflows from within Kubernetes

Vault Config Operator This operator helps set up Vault Configurations. The main intent is to do so such that subsequently pods can consume the secrets

Dec 19, 2022

kubectl plugin for generating nginx-ingress compatible basic-auth secrets on kubernetes clusters

kubectl-htpasswd kubectl plugin for easily generating hashed basic auth secrets. Supported hash algorithms bcrypt Examples Create the secret on the cl

Jul 17, 2022

A very simple, silly little kubectl plugin / utility that guesses which language an application running in a kubernetes pod was written in.

A very simple, silly little kubectl plugin / utility that guesses which language an application running in a kubernetes pod was written in.

Mar 9, 2022

A Terraform module to manage cluster authentication (aws-auth) for an Elastic Kubernetes (EKS) cluster on AWS.

Archive Notice The terraform-aws-modules/eks/aws v.18.20.0 release has brought back support aws-auth configmap! For this reason, I highly encourage us

Dec 4, 2022
Jan 4, 2022
vcluster - Create fully functional virtual Kubernetes clusters - Each cluster runs inside a Kubernetes namespace and can be started within seconds
vcluster - Create fully functional virtual Kubernetes clusters - Each cluster runs inside a Kubernetes namespace and can be started within seconds

Website • Quickstart • Documentation • Blog • Twitter • Slack vcluster - Virtual Clusters For Kubernetes Lightweight & Low-Overhead - Based on k3s, bu

Jan 4, 2023
kubectl-fzf provides a fast and powerful fzf autocompletion for kubectl
kubectl-fzf provides a fast and powerful fzf autocompletion for kubectl

Kubectl-fzf kubectl-fzf provides a fast and powerful fzf autocompletion for kubectl. Table of Contents Kubectl-fzf Table of Contents Features Requirem

Nov 3, 2021
Kubectl golang - kubectl krew template repo

kubectl krew template repo There's a lot of scaffolding needed to set up a good

Jan 11, 2022
A replacement for "kubectl exec" that works over WebSocket connections.

kubectl-execws A replacement for "kubectl exec" that works over WebSocket connections. Kubernetes API server has support for exec over WebSockets, but

Sep 23, 2022
kolm - Kubernetes on your local machine

kolm - Kubernetes on your local machine kolm is a tool for running a Kubernetes 'cluster' consisting of an etcd and a kube-apiserver on your local mac

May 19, 2022
An experimental Go application that allows an SSH session to interact with the clipboard of the host machine and forward calls to open

Remote Development Manager An experimental Go application that allows an SSH session to interact with the clipboard of the host machine and forward ca

Dec 27, 2022
A kubectl plugin for getting endoflife information about your cluster.
A kubectl plugin for getting endoflife information about your cluster.

kubectl-endoflife A kubectl plugin that checks your clusters for component compatibility and Kubernetes version end of life. This plugin is meant to a

Jul 21, 2022
cluster-api-state-metrics (CASM) is a service that listens to the Kubernetes API server and generates metrics about the state of custom resource objects related of Kubernetes Cluster API.

Overview cluster-api-state-metrics (CASM) is a service that listens to the Kubernetes API server and generates metrics about the state of custom resou

Oct 27, 2022
Rotate is a tool for rotating out AWS Auto-Scaling Groups within a k8s cluster

k8s-r8 rotate is a tool for rotating out AWS Auto-Scaling Groups within a k8s cluster. It was developed to make upgrading AMIs as a one command experi

Mar 27, 2022