use of io.kubernetes.client.ApiClient in project java by kubernetes-client.
the class Example method main.
public static void main(String[] args) throws IOException, ApiException {
ApiClient client = Config.defaultClient();
Configuration.setDefaultApiClient(client);
CoreV1Api api = new CoreV1Api();
V1PodList list = api.listPodForAllNamespaces(null, null, null, null, null, null, null, null, null);
for (V1Pod item : list.getItems()) {
System.out.println(item.getMetadata().getName());
}
}
use of io.kubernetes.client.ApiClient in project java by kubernetes-client.
the class ExecExample method main.
public static void main(String[] args) throws IOException, ApiException, InterruptedException {
String podName = "nginx-4217019353-k5sn9";
String namespace = "default";
List<String> commands = new ArrayList<>();
int len = args.length;
if (len >= 1)
podName = args[0];
if (len >= 2)
namespace = args[1];
for (int i = 2; i < len; i++) {
commands.add(args[i]);
}
ApiClient client = Config.defaultClient();
Configuration.setDefaultApiClient(client);
Exec exec = new Exec();
boolean tty = System.console() != null;
// final Process proc = exec.exec("default", "nginx-4217019353-k5sn9", new String[]
// {"sh", "-c", "echo foo"}, true, tty);
final Process proc = exec.exec(namespace, podName, commands.isEmpty() ? new String[] { "sh" } : commands.toArray(new String[commands.size()]), true, tty);
Thread in = new Thread(new Runnable() {
public void run() {
try {
ByteStreams.copy(System.in, proc.getOutputStream());
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
in.start();
Thread out = new Thread(new Runnable() {
public void run() {
try {
ByteStreams.copy(proc.getInputStream(), System.out);
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
out.start();
proc.waitFor();
// wait for any last output; no need to wait for input thread
out.join();
proc.destroy();
System.exit(proc.exitValue());
}
use of io.kubernetes.client.ApiClient in project java by kubernetes-client.
the class LogsExample method main.
public static void main(String[] args) throws IOException, ApiException, InterruptedException {
ApiClient client = Config.defaultClient();
Configuration.setDefaultApiClient(client);
CoreV1Api coreApi = new CoreV1Api(client);
PodLogs logs = new PodLogs();
V1Pod pod = coreApi.listNamespacedPod("default", "false", null, null, null, null, null, null, null, null).getItems().get(0);
InputStream is = logs.streamNamespacedPodLog(pod);
ByteStreams.copy(is, System.out);
}
use of io.kubernetes.client.ApiClient in project java by kubernetes-client.
the class AttachExample method main.
public static void main(String[] args) throws IOException, ApiException, InterruptedException {
ApiClient client = Config.defaultClient();
Configuration.setDefaultApiClient(client);
Attach attach = new Attach();
final Attach.AttachResult result = attach.attach("default", "nginx-4217019353-k5sn9", true);
new Thread(new Runnable() {
public void run() {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
OutputStream output = result.getStandardInputStream();
try {
while (true) {
String line = in.readLine();
output.write(line.getBytes());
output.write('\n');
output.flush();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
}).start();
new Thread(new Runnable() {
public void run() {
try {
ByteStreams.copy(result.getStandardOutputStream(), System.out);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}).start();
Thread.sleep(10 * 1000);
result.close();
System.exit(0);
}
Aggregations