我使用下面的代码行来获取有关特定 PVC 的详细信息
response = await `serverModule.kubeclient.api.v1.namespaces(ns).persistentvolumeclaims(pvc).get();`
上述调用对应的API为readNamespacedPersistentVolumeClaim格式如下
GET /api/v1/namespaces/{namespace}/persistentvolumeclaims/{name}
现在,我正在尝试调用readStorageClass使用与上面相同的约定
response = await serverModule.kubeclient.apis.storage.k8s.io.v1.storageclasses(sc).get();
正如您在链接中看到的,GET/apis/storage.k8s.io/v1/storageclasses/{name}
是格式,我使用了上面的语法。但由于某种原因,代码失败并出现错误
Exported kubeclient, ready to process requests
TypeError: Cannot read property 'k8s' of undefined
我犯的语法错误是什么?我尝试了各种组合,但没有成功。
最佳答案
本期列出PersistentVolumeClaim
是kubernetes的coreV1Api
的一部分,列出StorageClass
是StorageV1beta1Api
的一部分。下面是使用 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();
}
以下是官方文档链接供您引用:
希望这有帮助。
关于java - 如何使用 Kubernetes 客户端列出存储类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54115200/