Port Forwarding

Use case

You can use Port Forwarding to connect to databases or services within the cluster, which are not exposed outside the cluster.

You would then use your favorite tool to connect to a database, for example, by connecting to 127.0.0.1 and the local port you specified. The credentials you already know would be required, but the SSH tunnel is handled by the Bunnyshell CLI.

 

Overview

The bns port-forward command is the one needed to establish these port forwards.

It’s working similarly to kubectl port-forward, so it is not altering Kubernetes resources in any way.

There are two options in which you can use the command:

  • you would go through a wizard to get to the targeted port on the desired Component
  • specify the --component and --pod (if the resource has multiple pods)

 

Let's take some examples to showcase the functionality better.

 

Same local and remote port

In case you need to forward remote port 5432 to your machine on the same port, just run the command by only specifying the port.

$ bns port-forward 5432
? Select project Playground
? Select environment Bunnyshell Books
? Select component db
Forwarding ports to pod env-6pcfdl/db-6bd4c6fcdf-gddxp...

Forwarding from 127.0.0.1:5432 -> 5432

 

Specific local port

In case you need to forward remote port 5432 to your machine, to a specific local port, you must specify both the local and the remote ports.

$ bns port-forward 15432:5432
? Select project Playground
? Select environment Bunnyshell Books
? Select component db
Forwarding ports to pod env-6pcfdl/db-6bd4c6fcdf-gddxp...

Forwarding from 127.0.0.1:15432 -> 5432

 

Random local port

In case you need to forward remote port 5432 to your machine, but don't have a preference on the local port to be used, you could use :5432, and Bunnyshell will allocate a random (available) port.

$ bns port-forward :5432
? Select project Playground
? Select environment Bunnyshell Books
? Select component db
Forwarding ports to pod env-6pcfdl/db-6bd4c6fcdf-gddxp...

Forwarding from 127.0.0.1:57616 -> 5432

 

Opening multiple forwards in one go

To avoid opening up multiple processes, you can combine multiple forwards in a single command.

$ bns port-forward 15432:5432 5432 :5432
? Select project Playground
? Select environment Bunnyshell Books
? Select component db
Forwarding ports to pod env-6pcfdl/db-6bd4c6fcdf-gddxp...

Forwarding from 127.0.0.1:15432 -> 5432
Forwarding from 127.0.0.1:5432 -> 5432
Forwarding from 127.0.0.1:57643 -> 5432

 

Specifying the Component

If you want to skip the wizard, and run the command in a non-interactive way, you can specify the --component and even --pod (if the resource has multiple pods) and the wizard would be skipped.

$ bns port-forward :5432 --component Qb02Ryw034
Forwarding ports to pod env-6pcfdl/db-6bd4c6fcdf-gddxp...

Forwarding from 127.0.0.1:57609 -> 5432