簡體   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