使用 Java 操作 Kubernetes API,Java查看Servcie等资源的信息
@Test
public void CoreV1ApiTest(){
CoreV1Api apiInstance = new CoreV1Api();
String pretty = "true";
String _continue = "_continue_example";
String fieldSelector = "fieldSelector_example";
String labelSelector = "labelSelector_example";
Integer limit = 56;
String resourceVersion = "resourceVersion_example";
Integer timeoutSeconds = 56;
Boolean watch = true;
try {
// Namespace列表
V1NamespaceList result = apiInstance.listNamespace(null,pretty,null,null,null,null,null,null,null);
// Node列表
// V1NodeList result = apiInstance.listNode(null,pretty,null,null,null,null,null,null,null);
// Service列表
// V1ServiceList result = apiInstance.listNamespacedService("kube-system", null, null, null, null, null, null, null, null, null);
// Service 详情
// /api/v1/namespaces/kube-system/services/webapi-service
// V1Service result = apiInstance.readNamespacedService("flyapi-service", "kube-system", null, null, null);
System.out.println(result);
// JSON
Gson gson=new Gson();
String s = gson.toJson(result);
System.out.println(s);
} catch (ApiException e) {
System.err.println("Exception when calling CoreV1Api#listNode");
e.printStackTrace();
}
}