use of io.kubernetes.client.openapi.apis.CoreV1Api 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, null).getItems().get(0);
InputStream is = logs.streamNamespacedPodLog(pod);
Streams.copy(is, System.out);
}
use of io.kubernetes.client.openapi.apis.CoreV1Api in project java by kubernetes-client.
the class PagerExample method main.
public static void main(String[] args) throws IOException {
ApiClient client = Config.defaultClient();
OkHttpClient httpClient = client.getHttpClient().newBuilder().readTimeout(60, TimeUnit.SECONDS).build();
client.setHttpClient(httpClient);
Configuration.setDefaultApiClient(client);
CoreV1Api api = new CoreV1Api();
int i = 0;
Pager<V1Namespace, V1NamespaceList> pager = new Pager<V1Namespace, V1NamespaceList>((Pager.PagerParams param) -> {
try {
return api.listNamespaceCall(null, null, param.getContinueToken(), null, null, param.getLimit(), null, null, 1, null, null);
} catch (Exception e) {
throw new RuntimeException(e);
}
}, client, 10, V1NamespaceList.class);
for (V1Namespace namespace : pager) {
System.out.println(namespace.getMetadata().getName());
}
System.out.println("------------------");
}
use of io.kubernetes.client.openapi.apis.CoreV1Api in project java by kubernetes-client.
the class ExampleTest method exactUrlOnly.
@Test
public void exactUrlOnly() throws IOException, ApiException {
ApiClient client = new ApiClient();
client.setBasePath("http://localhost:" + PORT);
Configuration.setDefaultApiClient(client);
V1Namespace ns1 = new V1Namespace().metadata(new V1ObjectMeta().name("name"));
stubFor(get(urlEqualTo("/api/v1/namespaces/name")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(client.getJSON().serialize(ns1))));
CoreV1Api api = new CoreV1Api();
V1Namespace ns2 = api.readNamespace("name", null);
assertEquals(ns1, ns2);
}
use of io.kubernetes.client.openapi.apis.CoreV1Api 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, null);
for (V1Pod item : list.getItems()) {
System.out.println(item.getMetadata().getName());
}
}
use of io.kubernetes.client.openapi.apis.CoreV1Api in project java by kubernetes-client.
the class ExpandedExample method main.
/**
* Main method
*
* @param args
*/
public static void main(String[] args) {
try {
ApiClient client = Config.defaultClient();
// To change the context of k8s cluster, you can use
// io.kubernetes.client.util.KubeConfig
Configuration.setDefaultApiClient(client);
COREV1_API = new CoreV1Api(client);
// ScaleUp/ScaleDown the Deployment pod
// Please change the name of Deployment?
System.out.println("----- Scale Deployment Start -----");
scaleDeployment("account-service", 5);
// List all of the namaspaces and pods
List<String> nameSpaces = getAllNameSpaces();
nameSpaces.stream().forEach(namespace -> {
try {
System.out.println("----- " + namespace + " -----");
getNamespacedPod(namespace).stream().forEach(System.out::println);
} catch (ApiException ex) {
LOGGER.warn("Couldn't get the pods in namespace:" + namespace, ex);
}
});
// Print all of the Services
System.out.println("----- Print list all Services Start -----");
List<String> services = getServices();
services.stream().forEach(System.out::println);
System.out.println("----- Print list all Services End -----");
// Print log of specific pod. In this example show the first pod logs.
System.out.println("----- Print Log of Specific Pod Start -----");
String firstPodName = getPods().get(0);
printLog(DEFAULT_NAME_SPACE, firstPodName);
System.out.println("----- Print Log of Specific Pod End -----");
} catch (ApiException | IOException ex) {
LOGGER.warn("Exception had occured ", ex);
}
}
Aggregations