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);
}
Aggregations