title: Connect Java code with a bastion host in GCP
body: <p>I have successfully completed this tutorial:</p>
  <p><a href="https://cloud.google.com/kubernetes-engine/docs/tutorials/private-cluster-bastion" rel="nofollow noreferrer">https://cloud.google.com/kubernetes-engine/docs/tutorials/private-cluster-bastion</a></p>
  <p>Now that I have a bastion host running that connects to a private kubernetes cluster, I am looking for a way to use a java client to list the jobs that are running inside the cluster.</p>
  <p>I understand that in order to connect to the bastion host SSH must be used, for example locally this is achieved via the command:</p>
  <p>gcloud beta compute ssh INSTANCE_NAME <br />
  --tunnel-through-iap <br />
  --project=PROJECT_ID <br />
  --zone=COMPUTE_ZONE <br />
  -- -4 -L8888:localhost:8888 -N -q -f</p>
  <p>Now I did a bit of research and found the following java SSH client:</p>
  <p><a href="http://www.jcraft.com/jsch/" rel="nofollow noreferrer">http://www.jcraft.com/jsch/</a></p>
  <p>However when trying to connect I need to input the host, port and username, as is shown in the following tutorial:</p>
  <p><a href="https://www.baeldung.com/java-ssh-connection" rel="nofollow noreferrer">https://www.baeldung.com/java-ssh-connection</a></p>
  <p>The thing is that I know tinyproxy is listening on port 8888 in the bastion host but I have no idea what the ip address of the bastion host would be. I also ignore which username should be used to establish the connection.</p>
  <p>I have tried the following to get the ip address:</p>
  <p>hostname -I</p>
  <p>however when using this IP address I get the following exception:</p>
  <pre><code> java.net.ConnectException: Operation timed out (Connection timed out)
      at com.jcraft.jsch.Util.createSocket(Util.java:349)
      at com.jcraft.jsch.Session.connect(Session.java:215)
      at com.jcraft.jsch.Session.connect(Session.java:183)
      at bastion.host.Main.main(Main.java:11)
  Caused by: java.net.ConnectException: Operation timed out (Connection timed out)
      at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
      at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399)
      at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
      at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
      at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
      at java.base/java.net.Socket.connect(Socket.java:609)
      at java.base/java.net.Socket.connect(Socket.java:558)
      at java.base/java.net.Socket.&lt;init&gt;(Socket.java:454)
      at java.base/java.net.Socket.&lt;init&gt;(Socket.java:231)
      at com.jcraft.jsch.Util.createSocket(Util.java:343)
      ... 3 more
  
  </code></pre>
  <p>Is there a way to connect a java client with a tinyproxy instance running on GCP. The ultimate goal would be to be able to send kubectl commands from the java application, that is, to manipulate the control plane of the cluster behind the bastion host to create jobs and list the existing jobs.</p>