<p>I am developing a simple java app that show the pods of the cluster.</p>
<p>This is the app:</p>
<pre><code>import io.kubernetes.client.openapi.ApiClient;
import io.kubernetes.client.openapi.ApiException;
import io.kubernetes.client.openapi.Configuration;
import io.kubernetes.client.openapi.apis.CoreV1Api;
import io.kubernetes.client.openapi.models.V1Pod;
import io.kubernetes.client.openapi.models.V1PodList;
import io.kubernetes.client.util.ClientBuilder;
import io.kubernetes.client.util.KubeConfig;
import java.io.FileReader;
import java.io.IOException;

/**
 * A simple example of how to use the Java API from an application outside a kubernetes cluster
 *
 * &lt;p&gt;Easiest way to run this: mvn exec:java
 * -Dexec.mainClass=&quot;io.kubernetes.client.examples.KubeConfigFileClientExample&quot;
 *
 */
public class untitled4 {
    public static void main(String[] args) throws IOException, ApiException {

        // file path to your KubeConfig
        String kubeConfigPath = &quot;/home/robin/.kube/config&quot;;

        // loading the out-of-cluster config, a kubeconfig from file-system
        ApiClient client =
                ClientBuilder.kubeconfig(KubeConfig.loadKubeConfig(new FileReader(kubeConfigPath))).build();

        // set the global default api-client to the in-cluster one from above
        Configuration.setDefaultApiClient(client);

        // the CoreV1Api loads default api-client from global configuration.
        CoreV1Api api = new CoreV1Api();

        // invokes the CoreV1Api client
        V1PodList list = api.listPodForAllNamespaces(null, null, null, null, null, null, null, null, null);
        System.out.println(&quot;Listing all pods: &quot;);
        for (V1Pod item : list.getItems()) {
            System.out.println(item.getMetadata().getName());
        }
    }
}
</code></pre>
<p>But I get this error:</p>
<pre><code>Exception in thread &quot;main&quot; java.lang.IllegalStateException: Unimplemented
    at io.kubernetes.client.util.authenticators.GCPAuthenticator.refresh(GCPAuthenticator.java:61)
    at io.kubernetes.client.util.KubeConfig.getAccessToken(KubeConfig.java:215)
    at io.kubernetes.client.util.credentials.KubeconfigAuthentication.&lt;init&gt;(KubeconfigAuthentication.java:46)
    at io.kubernetes.client.util.ClientBuilder.kubeconfig(ClientBuilder.java:276)
    at untitled4.main(untitled4.java:28)

Process finished with exit code 1
</code></pre>

xRobot
<p>There is <a href="https://github.com/kubernetes-client/java/issues/290" rel="nofollow noreferrer">an open issue</a> on <strong>GitHub</strong> related with this problem. For now you can use workarounds like the one, proposed by <a href="https://github.com/jhbae200" rel="nofollow noreferrer">jhbae200</a> in <a href="https://github.com/kubernetes-client/java/issues/290#issuecomment-480205118" rel="nofollow noreferrer">this comment</a>:</p>
<blockquote>
<p>I am using it like this.</p>
<pre><code>package kubernetes.gcp;

import com.google.auth.oauth2.AccessToken;
import com.google.auth.oauth2.GoogleCredentials;
import io.kubernetes.client.util.KubeConfig;
import io.kubernetes.client.util.authenticators.Authenticator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.time.Instant;
import java.util.Date;
import java.util.Map;

public class ReplacedGCPAuthenticator implements Authenticator {
    private static final Logger log;
    private static final String ACCESS_TOKEN = &quot;access-token&quot;;
    private static final String EXPIRY = &quot;expiry&quot;;

    static {
        log = LoggerFactory.getLogger(io.kubernetes.client.util.authenticators.GCPAuthenticator.class);
    }

    private final GoogleCredentials credentials;

    public ReplacedGCPAuthenticator(GoogleCredentials credentials) {
        this.credentials = credentials;
    }

    public String getName() {
        return &quot;gcp&quot;;
    }

    public String getToken(Map&lt;String, Object&gt; config) {
        return (String) config.get(&quot;access-token&quot;);
    }

    public boolean isExpired(Map&lt;String, Object&gt; config) {
        Object expiryObj = config.get(&quot;expiry&quot;);
        Instant expiry = null;
        if (expiryObj instanceof Date) {
            expiry = ((Date) expiryObj).toInstant();
        } else if (expiryObj instanceof Instant) {
            expiry = (Instant) expiryObj;
        } else {
            if (!(expiryObj instanceof String)) {
                throw new RuntimeException(&quot;Unexpected object type: &quot; + expiryObj.getClass());
            }

            expiry = Instant.parse((String) expiryObj);
        }

        return expiry != null &amp;&amp; expiry.compareTo(Instant.now()) &lt;= 0;
    }

    public Map&lt;String, Object&gt; refresh(Map&lt;String, Object&gt; config) {
        try {
            AccessToken accessToken = this.credentials.refreshAccessToken();

            config.put(ACCESS_TOKEN, accessToken.getTokenValue());
            config.put(EXPIRY, accessToken.getExpirationTime());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return config;
    }
}
</code></pre>
<p>Running in.</p>
<pre><code>//GoogleCredentials.fromStream(--something credential.json filestream--)
KubeConfig.registerAuthenticator(new ReplacedGCPAuthenticator(GoogleCredentials.getApplicationDefault()));
ApiClient client = Config.defaultClient();
Configuration.setDefaultApiClient(client);
CoreV1Api api = new CoreV1Api();
V1PodList list = api.listNamespacedPod(&quot;default&quot;, null, null, null, null, null, null, null, 30, Boolean.FALSE);
for (V1Pod item : list.getItems()) {
    System.out.println(item.getMetadata().getName());
}
</code></pre>
</blockquote>
