<p>My application using client-java-8.0.2.jar and java 1.8.0_252 version. I am getting the following error while creating Pod using the following code,</p>

<p>Code:</p>

<pre><code>// get the default api-client
ApiClient client = Config.defaultClient();

Configuration.setDefaultApiClient(client);

CoreV1Api api = new CoreV1Api();

List&lt;V1EnvVar&gt; envVariables = new ArrayList&lt;V1EnvVar&gt;();
for (Map.Entry&lt;String, String&gt; 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);
</code></pre>

<p><strong>Error:</strong></p>

<pre><code>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]
</code></pre>

<p>Any inputs here really appreciated.</p>

<p>The answer is cluster name should be "lower case alphanumeric characters"</p>

<p>I tried to debug this issue using the following code,</p>

<p>My updated code,</p>

<pre><code>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());
}
</code></pre>

<p>Error:</p>

<pre><code>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
}
</code></pre>
