title: Access OpenShift forwarded ports from remote host
body: <p>I would like to connect to a PostgreSQL (9.6) cluster that runs inside OpenShift (3.9) using port forwarding as described <a href="https://blog.openshift.com/openshift-connecting-database-using-port-forwarding/" rel="nofollow noreferrer">here</a>. To this end I set up and sanity-check port forwarding on a jump host (outside the OpenShift cluster) like this:</p>
  
  <pre><code>oc port-forward $pod 5432:5432
  netstat -ln | grep 5432 # "tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN"
  psql -U postgres -h localhost # OK
  psql -U postgres -h $(hostname -i) # error: "connection refused"
  </code></pre>
  
  <p>So it looks as if port forwarding listens only for <code>localhost</code>, but not the host's other IP address(es). Ultimately I want to connect to the database thru the jump host from another remote hosts, so `localhost' won't suffice.</p>
  
  <p>How can I set up (OpenShift) port forwarding in such a way that it will allow access to the forwarded port from remote hosts as well? I suppose Iptables (in combination with OpenShift port forwarding) could do the trick, but I do not yet know how and if there is a simpler approach. (The jump host runs Debian 9.5.)</p>
  
  <p><strong>UPDATE</strong> An approach combining an SSH tunnel and OpenShift (Kubernetes) port forwarding apparently can solve this. This was suggested in a link provided in the accepted answer below.</p>
  
  <p>on jump host (1st session):</p>
  
  <pre><code>ssh -N -L $(hostname -i):5432:localhost:5433 $(whoami)@$(hostname)
  </code></pre>
  
  <p>on jump host (2nd session):</p>
  
  <pre><code>oc port-forward $pod 5433:5432
  </code></pre>
  
  <p>on remote host:</p>
  
  <pre><code>psql -U postgres -h jump-host
  </code></pre>