According to this, I can specify system property KUBECONFIG to tell defaultKubernetesClient to use the specified kubeconfig file instead of the default ~/.kube/configfile.
What should I do that then I'm using fabric8io?
Tks in advance.
It looks like there is a typo in the blogpost, If I look at Fabric8 code Config.java, property name is kubeconfig not KUBECONFIG.
I moved my .kube/config file to /tmp/mykubeconfig and then I tested with the following code on minikube and it seemed to be working okay
System.setProperty("kubeconfig", "/tmp/mykubeconfig");
try (KubernetesClient kubernetesClient = new DefaultKubernetesClient()) {
kubernetesClient.pods().inAnyNamespace().list().getItems().stream()
.map(Pod::getMetadata)
.map(ObjectMeta::getName)
.forEach(System.out::println);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With