gpt4 book ai didi

java - 创建 Pod 集群时获取 ApiException

转载 作者:行者123 更新时间:2023-12-01 13:37:17 26 4
gpt4 key购买 nike

我的应用程序使用 client-java-8.0.2.jar 和 java 1.8.0_252 版本。使用以下代码创建 Pod 时出现以下错误,

代码:

// get the default api-client
ApiClient client = Config.defaultClient();

Configuration.setDefaultApiClient(client);

CoreV1Api api = new CoreV1Api();

List<V1EnvVar> envVariables = new ArrayList<V1EnvVar>();
for (Map.Entry<String, String> entry : attributes.entrySet()) {
V1EnvVar env = new V1EnvVar();
env.setName(entry.getKey());
env.setValue(entry.getValue());
envVariables.add(env);
}
// create pod of a Kubernetes cluster
V1Pod pod = new V1PodBuilder().withNewMetadata().withName(serviceName).endMetadata().withNewSpec()
.addNewContainer().addAllToEnv(envVariables).withName("www").withImage(dockerImage).endContainer()
.endSpec().build();

pod = api.createNamespacedPod("default", pod, null, null, null);

错误:
Error while creating the cluster: 

io.kubernetes.client.openapi.ApiException:
at io.kubernetes.client.openapi.ApiClient.handleResponse(ApiClient.java:979) ~[client-java-api-8.0.2.jar!/:na]
at io.kubernetes.client.openapi.ApiClient.execute(ApiClient.java:895) ~[client-java-api-8.0.2.jar!/:na]
at io.kubernetes.client.openapi.apis.CoreV1Api.createNamespacedPodWithHttpInfo(CoreV1Api.java:7902) ~[client-java-api-8.0.2.jar!/:na]
at io.kubernetes.client.openapi.apis.CoreV1Api.createNamespacedPod(CoreV1Api.java:7876) ~[client-java-api-8.0.2.jar!/:na]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_252]

这里的任何输入都非常感谢。

最佳答案

答案是集群名称应该是“小写字母数字字符”

我尝试使用以下代码调试此问题,

我更新的代码,

try {
pod = api.createNamespacedPod("default", pod, null, null, null);
LOGGER.debug(String.format("Cluster with name \"%s\" created successfully", pod.getMetadata().getName()));
} catch (ApiException ae) {
LOGGER.error("API EXCEPTION: " + ae.getResponseBody());
}

错误:
API EXCEPTION: {
"kind": "Status",
"apiVersion": "v1",
"metadata": {

},
"status": "Failure",
"message": "Pod \"Sample\" is invalid: metadata.name: Invalid value: \"Sample\": a DNS-1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')",
"reason": "Invalid",
"details": {
"name": "Sample",
"kind": "Pod",
"causes": [
{
"reason": "FieldValueInvalid",
"message": "Invalid value: \"Sample\": a DNS-1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')",
"field": "metadata.name"
}
]
},
"code": 422
}

关于java - 创建 Pod 集群时获取 ApiException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62280629/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com