I have below code, that I am running on laptop:
public class PodDeployment {
public void deploy() throws ApiException, IOException {
ApiClient client = Config.defaultClient();
Configuration.setDefaultApiClient(client);
CoreV1Api api = new CoreV1Api(client);
V1Container container = new V1Container();
container.setName("nginxcontainer");
container.setImage("nginx:latest");
V1PodSpec podSpec = new V1PodSpec();
podSpec.setContainers(List.of(container));
V1Pod pod = new V1Pod();
pod.setSpec(podSpec);
pod.setMetadata(new V1ObjectMeta().name("nginxcontainer"));
pod.apiVersion("v1");
pod.kind("Pod");
var result = api.createNamespacedPod("myns", pod, "true", "true", null, null);
System.out.println("Pod created: " + result.getMetadata().getName());
// Create a new Deployment
}
}
My creds that I have in .kube/config are fine as I can do kubectl apply....
and create a pod, etc. So I do not think it is the creds
I see below error without much info as to what is invalid in my request(how do I get details)
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See .html#StaticLoggerBinder for further details.
Exception in thread "main" io.kubernetes.client.openapi.ApiException: Unprocessable Entity
at io.kubernetes.client.openapi.ApiClient.handleResponse(ApiClient.java:973)
at io.kubernetes.client.openapi.ApiClient.execute(ApiClient.java:885)
at io.kubernetes.client.openapi.apis.CoreV1Api.createNamespacedPodWithHttpInfo(CoreV1Api.java:10251)
at io.kubernetes.client.openapi.apis.CoreV1Api.createNamespacedPod(CoreV1Api.java:10203)
at com.mypackage.PodDeployment.deploy(PodDeployment.java:31)
at com.mypackage.Main.main(Main.java:22)