DEV Community


Posted on

Fast Knowledge: Kubernetes port forwarding

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
Enter fullscreen mode Exit fullscreen mode

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

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


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

Enter fullscreen mode Exit fullscreen mode

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

Top comments (1)

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.