A simple guide for port forwarding Kubernetes resources

Alex Barashkov - Aug 12 '19 - - Dev Community

Kubernetes changes the way how people deploy, orchestrate, and build their infrastructures. In this article, we will learn the simplest way of accessing your internal Kubernetes resources from your local machine.

πŸ’Ό Use case

You deployed PostgreSQL to your cluster, and you don't want to expose it publicly, but want to make some queries and access DB.

πŸŽ‰ Solution

Use Kubernetes native port-forwarding functionality. Specific Kubernetes API allows creating a tunnel from your cluster resource to your localhost over a single HTTP connection. As a result, you can access at your localhost 5432 port PostgreSQL from your Kubernetes cluster.

You could do it with kubectl,

kubectl port-forward -n default deployment/postgres 8432:5432
Enter fullscreen mode Exit fullscreen mode

or you could use very simple open-source GUI – Kube Forwarder. Having CLI tool is excellent, but it does not have a few essential features

  • Auto-reconnect(if your connection is not so stable, you will have manually rerun the command)
  • Auto-complete(you always need to keep in mind names of your services, namespaces, I had some hints in notes)
  • Multiple cluster support (switch context each time you want to forward something is not a great experience as well)

So keeping that in mind we developed Kube Forwarder – easy to use Kubernetes port-forwarding manager.

Other important features we have:

  • Auto-import of kube config clusters
  • Import/Export all bookmarked clusters and resources(works well for sharing it with the team)
  • Forward multiple services at the same time
  • Zero native dependencies (works without kubectl CLI)

How to forward resources with Kube Forwarder❓

It's very simple three steps process if you do it first time –

  • Add a cluster configuration
  • Find resource you want to forward
  • Start forwarding

Add a cluster configuration

If you already have kubeconfig file, Kube Forwarder will suggest you to import clusters you have:

We also have other options:

  • Add clusters by choosing one or multiple files
  • Paste your config as a plain text. It could be useful if you created a new cluster and want to get access to some deployments
  • Restore the configuration from Kube Forwarder JSON. Useful when you as a devops want to prepare easy to use forwarding for your dev team who are not well familiar with Kubernetes.

Find the resource you want to forward

Kube Forwarder has autocomplete by namespaces, pods, deployments, so it makes the process of adding a new resource for forwarding very simple.

Set as a local port - port from your local machine and resource port – the port where your app launched. Other fields I think don't need extra clarification.
Once you added the resource - press "Play" button and access your service from your local machine.

πŸ™ We're looking for your feedback

We believe that apps like this could make you more productive and attract more people to start using Kubernetes. Let us know what do you think about the app and your ideas how could we make it better.

We built the app with Electron, so it works well on macOS, Windows and Linux.

Github - ⭐ https://github.com/pixel-point/kube-forwarder

. . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player