Search in sources :

Example 6 with ApiClient

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());
    }
}
Also used : V1PodList(io.kubernetes.client.models.V1PodList) V1Pod(io.kubernetes.client.models.V1Pod) ApiClient(io.kubernetes.client.ApiClient) CoreV1Api(io.kubernetes.client.apis.CoreV1Api)

Example 7 with ApiClient

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());
}
Also used : Exec(io.kubernetes.client.Exec) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ApiClient(io.kubernetes.client.ApiClient)

Example 8 with ApiClient

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);
}
Also used : PodLogs(io.kubernetes.client.PodLogs) InputStream(java.io.InputStream) V1Pod(io.kubernetes.client.models.V1Pod) ApiClient(io.kubernetes.client.ApiClient) CoreV1Api(io.kubernetes.client.apis.CoreV1Api)

Example 9 with ApiClient

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);
}
Also used : InputStreamReader(java.io.InputStreamReader) Attach(io.kubernetes.client.Attach) OutputStream(java.io.OutputStream) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) ApiClient(io.kubernetes.client.ApiClient)

Aggregations

ApiClient (io.kubernetes.client.ApiClient)9 IOException (java.io.IOException)4 CoreV1Api (io.kubernetes.client.apis.CoreV1Api)3 ArrayList (java.util.ArrayList)3 V1Pod (io.kubernetes.client.models.V1Pod)2 BufferedReader (java.io.BufferedReader)2 InputStream (java.io.InputStream)2 JsonObject (com.google.gson.JsonObject)1 TypeToken (com.google.gson.reflect.TypeToken)1 WebSocket (com.squareup.okhttp.ws.WebSocket)1 ApiException (io.kubernetes.client.ApiException)1 Attach (io.kubernetes.client.Attach)1 Exec (io.kubernetes.client.Exec)1 PodLogs (io.kubernetes.client.PodLogs)1 PortForward (io.kubernetes.client.PortForward)1 ProtoClient (io.kubernetes.client.ProtoClient)1 ExtensionsV1beta1Deployment (io.kubernetes.client.models.ExtensionsV1beta1Deployment)1 V1Namespace (io.kubernetes.client.models.V1Namespace)1 V1PodList (io.kubernetes.client.models.V1PodList)1 Namespace (io.kubernetes.client.proto.V1.Namespace)1