I am using Kubernetes Java client API https://github.com/kubernetes-client/java for fetching all namespaces present. I am Getting Error-
io.kubernetes.client.ApiException: java.net.ConnectException: Failed to connect to localhost/127.0.0.1:443
at io.kubernetes.client.ApiClient.execute(ApiClient.java:801)
at io.kubernetes.client.apis.CoreV1Api.listNamespaceWithHttpInfo(CoreV1Api.java:15939)
at io.kubernetes.client.apis.CoreV1Api.listNamespace(CoreV1Api.java:15917)
at com.cloud.kubernetes.KubernetesNamespacesAPI.fetchAllNamespaces(KubernetesNamespacesAPI.java:25)
at com.cloud.spark.sharedvariable.ClouzerConfigurations.setKubernetesEnvironment(ClouzerConfigurations.java:45)
I tried creating cluster role binding and giving permission to the user.
Here is my code snippet:
public static List<String> fetchAllNamespaces(){
try {
return COREV1_API.listNamespace(null, "true", null, null, null, 0, null, Integer.MAX_VALUE, Boolean.FALSE)
.getItems().stream().map(v1Namespace -> v1Namespace.getMetadata().getName())
.collect(Collectors.toList());
}catch(Exception e) {
e.printStackTrace();
return new ArrayList<>();
}
}
Please let me know if I am missing anything. Thanks in advance.