kubectl port-forward to another endpoint

4/16/2020

Is there a corresponding command with kubectl to:

ssh -L8888:rds.aws.com:5432 example.com

kubectl has port-forward you can also specify --address but that strictly requires an IP address.

-- Mahoni
kubernetes
portforwarding
tunnel

1 Answer

4/17/2020

Short answer, No.

In OpenSSH, local port forwarding is configured using the -L option:

   ssh -L 80:intra.example.com:80 gw.example.com

This example opens a connection to the gw.example.com jump server, and forwards any connection to port 80 on the local machine to port 80 on intra.example.com.

By default, anyone (even on different machines) can connect to the specified port on the SSH client machine. However, this can be restricted to programs on the same host by supplying a bind address:

   ssh -L 127.0.0.1:80:intra.example.com:80 gw.example.com

You can read the docs here.

The port-forward in Kubernetes works only within the cluster, you can forward traffic that will hit specified port to Deployment or Service or a Pod

kubectl port-forward TYPE/NAME [options] [LOCAL_PORT:]REMOTE_PORT [...[LOCAL_PORT_N:]REMOTE_PORT_N]

--address flag is to specify what to listen on 0.0.0.0 means everything localhost is as name and you can set an IP on which it can be listening on. Documentation is available here, you can also read Use Port Forwarding to Access Applications in a Cluster.

-- Crou
Source: StackOverflow