繁体   English   中英

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

[英]How to list storage classes using Kubernetes client

我正在使用以下代码行来获取有关特定PVC的详细信息

response = await `serverModule.kubeclient.api.v1.namespaces(ns).persistentvolumeclaims(pvc).get();`

上面调用的相应API为readNamespacedPersistentVolumeClaim ,格式如下

GET /api/v1/namespaces/{namespace}/persistentvolumeclaims/{name}

现在,我正在尝试使用与上述相同的约定来调用readStorageClass

响应=等待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

我犯了什么语法错误。 我尝试了各种组合,但均无效果。

此问题列出了PersistentVolumeClaimcoreV1Api的coreV1Api的一部分,列出了StorageClassStorageV1beta1Api的一部分。 接下来是使用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();
}

以下是官方文档链接供您参考:

https://github.com/kubernetes-client/java/blob/master/kubernetes/docs/StorageV1beta1Api.md#listStorageClass

希望这可以帮助。

使用client.apis["storage.k8s.io"].v1.storageclasses.get() ,适用于任何包含点的api。 希望能帮助到你

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM