Search in sources :

Example 1 with PortForward

use of io.kubernetes.client.PortForward in project java by kubernetes-client.

the class PortForwardExample method main.

public static void main(String[] args) throws IOException, ApiException, InterruptedException {
    ApiClient client = Config.defaultClient();
    Configuration.setDefaultApiClient(client);
    PortForward forward = new PortForward();
    List<Integer> ports = new ArrayList<>();
    ports.add(8080);
    ports.add(80);
    final PortForward.PortForwardResult result = forward.forward("default", "nginx-d5dc44cf7-x7475", ports);
    ServerSocket ss = new ServerSocket(8080);
    final Socket s = ss.accept();
    System.out.println("Connected!");
    new Thread(new Runnable() {

        public void run() {
            try {
                ByteStreams.copy(result.getInputStream(80), s.getOutputStream());
            } catch (IOException ex) {
                ex.printStackTrace();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }).start();
    new Thread(new Runnable() {

        public void run() {
            try {
                ByteStreams.copy(s.getInputStream(), result.getOutboundStream(80));
            } catch (IOException ex) {
                ex.printStackTrace();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }).start();
    Thread.sleep(10 * 1000);
    System.exit(0);
}
Also used : ArrayList(java.util.ArrayList) PortForward(io.kubernetes.client.PortForward) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) ApiClient(io.kubernetes.client.ApiClient) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket) ApiException(io.kubernetes.client.ApiException) IOException(java.io.IOException)

Aggregations

ApiClient (io.kubernetes.client.ApiClient)1 ApiException (io.kubernetes.client.ApiException)1 PortForward (io.kubernetes.client.PortForward)1 IOException (java.io.IOException)1 ServerSocket (java.net.ServerSocket)1 Socket (java.net.Socket)1 ArrayList (java.util.ArrayList)1