Java 如何使用Kubernetes客户端列出存储类

Java 如何使用Kubernetes客户端列出存储类,java,node.js,api,kubernetes,Java,Node.js,Api,Kubernetes,我使用下面的代码行来获取关于特定PVC的详细信息 response = await `serverModule.kubeclient.api.v1.namespaces(ns).persistentvolumeclaims(pvc).get();` 上述调用对应的API格式如下 GET /api/v1/namespaces/{namespace}/persistentvolumeclaims/{name} 现在,我尝试使用与上面相同的约定调用 response=wait serverModu

我使用下面的代码行来获取关于特定PVC的详细信息

response = await `serverModule.kubeclient.api.v1.namespaces(ns).persistentvolumeclaims(pvc).get();`
上述调用对应的API格式如下

GET /api/v1/namespaces/{namespace}/persistentvolumeclaims/{name}
现在,我尝试使用与上面相同的约定调用


response=wait serverModule.kubeclient.api.storage.k8s.io.v1.storageclasses(sc.get()

正如您在链接中看到的,
GET/api/storage.k8s.io/v1/storageclasses/{name}
是我使用的上述语法的格式。但由于某种原因,代码会出错

Exported kubeclient, ready to process requests
TypeError: Cannot read property 'k8s' of undefined

我犯的语法错误是什么。我尝试了各种组合,但都没有成功。

此问题列出了
PersistentVolumeClaim
是kubernetes的
coreV1Api
的一部分,而清单
StorageClass
StorageV1betaAPI
的一部分。下面是使用JAVA客户端列出存储类的最简单代码:

ApiClient defaultClient = Configuration.getDefaultApiClient();

// Configure API key authorization: BearerToken
ApiKeyAuth BearerToken = (ApiKeyAuth) defaultClient.getAuthentication("BearerToken");
BearerToken.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//BearerToken.setApiKeyPrefix("Token");

StorageV1beta1Api apiInstance = new StorageV1beta1Api();
try {
    V1beta1StorageClassList result = apiInstance.listStorageClass();
    System.out.println(result);
} catch (ApiException e) {
    System.err.println("Exception when calling StorageV1beta1Api#listStorageClass");
    e.printStackTrace();
}
以下是供您参考的官方文档链接:


希望这有帮助。

本期所列的
PersistentVolumeClaim
是kubernetes的
coreV1Api
的一部分,而清单
StorageClass
StorageV1betaAPI
的一部分。下面是使用JAVA客户端列出存储类的最简单代码:

ApiClient defaultClient = Configuration.getDefaultApiClient();

// Configure API key authorization: BearerToken
ApiKeyAuth BearerToken = (ApiKeyAuth) defaultClient.getAuthentication("BearerToken");
BearerToken.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//BearerToken.setApiKeyPrefix("Token");

StorageV1beta1Api apiInstance = new StorageV1beta1Api();
try {
    V1beta1StorageClassList result = apiInstance.listStorageClass();
    System.out.println(result);
} catch (ApiException e) {
    System.err.println("Exception when calling StorageV1beta1Api#listStorageClass");
    e.printStackTrace();
}
以下是供您参考的官方文档链接:

希望这能有所帮助。

使用
client.api[“storage.k8s.io”].v1.storageclasses.get()
,适用于任何包含dots的api。 希望它能帮助使用
client.api[“storage.k8s.io”].v1.storageclasses.get()
,适用于任何包含dots的api。
希望它有帮助

我正在使用
js
进行api调用。可能是一些语法问题。如果您注意到,PVC代码的工作部分有以下API约定“/API/v1/namespaces/{namespaces}/persistentvolumeclaims/{name}”,而我对应的代码是“serverModule.kubeclient.API.v1.namespaces(ns).persistentvolumeclaims(PVC).get();”。失败的代码有API“/API/storage.k8s.io/v1/storageclasses/{name}”,我为其编写了“serverModule.kubeclient.API.storage.k8s.io.v1.storageclasses(sc.get();”。有些地方无法使用“api.storage.k8s.v1”。请指出您正在使用的k8s客户端的github。仅在javascript中,我就可以找到多个客户机,这些客户机有不同的方式调用APII,我正在使用“npm install@kubernetes/client node”来安装客户机。我假设这是github链接“”,我正在使用
js
进行api调用。可能是一些语法问题。如果您注意到,PVC代码的工作部分有以下API约定“/API/v1/namespaces/{namespaces}/persistentvolumeclaims/{name}”,而我对应的代码是“serverModule.kubeclient.API.v1.namespaces(ns).persistentvolumeclaims(PVC).get();”。失败的代码有API“/API/storage.k8s.io/v1/storageclasses/{name}”,我为其编写了“serverModule.kubeclient.API.storage.k8s.io.v1.storageclasses(sc.get();”。有些地方无法使用“api.storage.k8s.v1”。请指出您正在使用的k8s客户端的github。仅在javascript中,我就可以找到多个客户机,这些客户机有不同的方式调用APII,我正在使用“npm install@kubernetes/client node”来安装客户机。我假设这是github链接“”response=wait serverModule.kubeclient.api。[“storage.k8s.io”].v1.storageclasses(sc.get();^SyntaxError:API后面不应该有点(.)。正确的语法文本是:response=await serverModule.kubeclient.api[“storage.k8s.io”].v1.storageclasses(sc.get();response=await serverModule.kubeclient.api[“storage.k8s.io”].v1.storageclasses(sc.get());^SyntaxError:意外的标记[在API之后不应该有点(.)。正确的syntext是:response=wait serverModule.kubeclient.api[“storage.k8s.io”].v1.storageclasses(sc.get();