Closed yousefZw closed 4 months ago
Not sure but check your current-context
you can check by kubectl config view
I've managed to resolve the issue through debugging, and it's now working correctly for me:
final String userHome = System.getProperty("user.home");
// file path to your KubeConfig
String kubeConfigPath = String.format("%s/.kube/config-files/cxxxx.kubeconfig", userHome);
KubeConfig config = KubeConfig.loadKubeConfig(new InputStreamReader(new FileInputStream(kubeConfigPath), StandardCharsets.UTF_8));
// Solution: Refer to the KubeConfig details in the issue description.
// This specifies the context name from the config file.
config.setContext("demo-staging");
ApiClient client = ClientBuilder.kubeconfig(config).build();
Configuration.setDefaultApiClient(client);
you can check by
kubectl config view
Thank you! I've found the solution, which you can see in my comment. It turns out that 'KubeConfig' requires the context name in order to retrieve the server name. This wasn't being initialized properly in the 'loadKubeConfig' method. I hope I got that right, but it now works after I set the context with the name separately.
Thank you. Please close the issue
See solution in comments above.
Describe the bug When attempting to create a client using a specific "KubeConfig", I encounter the following error message:
Java Version graalvm-jdk-22.0.1_8.1 **OS Version*** Windows 11
Client Version
20.0.0
Kubernetes Version
1.28+
Server Version: version.Info{Major:"1", Minor:"28+", GitVersion:"v1.28.8-caas"To Reproduce See Code.
Code
POM.XML
KubeConfig
Server (please complete the following information):
Additional context Add any other context about the problem here.