[英]How to create general Kubernetes objects from yaml using Java client
[英]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
我犯了什么語法錯誤。 我嘗試了各種組合,但均無效果。
此問題列出了PersistentVolumeClaim
是coreV1Api
的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();
}
以下是官方文檔鏈接供您參考:
希望這可以幫助。
使用client.apis["storage.k8s.io"].v1.storageclasses.get()
,適用於任何包含點的api。 希望能幫助到你
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.