<p>According to <a href="https://developers.redhat.com/blog/2020/05/20/getting-started-with-the-fabric8-kubernetes-java-client" rel="nofollow noreferrer">this</a>, I can specify system property <em>KUBECONFIG</em> to tell defaultKubernetesClient to use the specified kubeconfig file instead of the default <code>~/.kube/config</code>file.
<br>What should I do that then I'm using fabric8io?
<br>Tks in advance.</p>

theotheo
<p>It looks like there is a typo in the blogpost, If I look at Fabric8 code <a href="https://github.com/fabric8io/kubernetes-client/blob/master/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/Config.java#L113" rel="nofollow noreferrer">Config.java</a>, property name is <code>kubeconfig</code> not <code>KUBECONFIG</code>.</p>
<p>I moved my <code>.kube/config</code> file to <code>/tmp/mykubeconfig</code> and then I tested with the following code on <a href="https://github.com/kubernetes/minikube" rel="nofollow noreferrer">minikube</a> and it seemed to be working okay</p>
<pre class="lang-java prettyprint-override"><code>System.setProperty(&quot;kubeconfig&quot;, &quot;/tmp/mykubeconfig&quot;);
try (KubernetesClient kubernetesClient = new DefaultKubernetesClient()) {
    kubernetesClient.pods().inAnyNamespace().list().getItems().stream()
            .map(Pod::getMetadata)
            .map(ObjectMeta::getName)
            .forEach(System.out::println);
}
</code></pre>
