DEV Community

loading...

Fast Knowledge: Kubernetes port forwarding

mfahlandt profile image Mario ・1 min read

When i finally discovered the option in Kubernetes to forward a port of a pod to localhost, it changed the way i started working with my cluster.

I often have my MongoDB, MYSQL or Elasticsearch inside of a Kubernetes cluster, running on pods. Naturally it has no public access point or port forwarding to the outside of the cluster. But sometimes you want to use a Client to access your Database or you want to use your cli locally to find errors.

The solution is

kubectl port-forward localport:podport

This allows you to easily forward your mongoDB Port to localhost for example

kubectl port-forward pods/mongo-0 27017:27017

or

kubectl port-forward deployment/mongo-0 27017:27017


Then you can use use your MongoDB Client (e.g Robo 3T) to connect to localhost:27017 and you are connected to your remote NOSQL Database.

For more information look here

Discussion

pic
Editor guide
Collapse
alex_barashkov profile image
Alex Barashkov

Hi Mario, highly recommend you take a look at our open-source app for Kubernetes port forwarding. I think we made the process of using port-forwarding much better.