java - 如何使用 Kubernetes 客户端列出存储类
问题描述
我正在使用下面的代码行来获取有关特定 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
KubernetesStorageClass
的一部分,列表是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();
}
以下是官方文档链接供您参考:
希望这可以帮助。
推荐阅读
- android - 片段被视图分页器布局切割
- google-maps - 获取边界框的 TMS 服务的 {X} 和 {Y} 值
- python - 使用动态文本框生成动态生成 AngularJS 表单
- android - Android编程imei getDeviceID(telephonymanager)
- python - 在点列表中计算到其邻居的最短距离
- javascript - 如何将元素移动到另一个父级,保持其状态和 DOM?
- c - STM32F401RE Nucleo 板,无法切换用户 LED
- reactjs - saga 可以在我们刷新浏览器的时候执行这个函数吗?
- mysql - 具有动态列的单表 MySQL Pivot
- c++ - 将带有字段的表作为参数从 C++ 传递给 Lua 函数?