<p>when i run this code
public class test2 {</p>

<pre><code>public static void main(String[] args) {
    // TODO Auto-generated method stub


      String podName = "xrdpprocan";
      String namespace = "default";
      String master = "https://my_ip_adress"; 

      Config config = new ConfigBuilder().withMasterUrl(master).withTrustCerts(true).build();
      try (final KubernetesClient client = new DefaultKubernetesClient(config)) {

        String log = client.pods().inNamespace(namespace).withName(podName).getLog(true);
        System.out.println("Log of pod " + podName + " in " + namespace + " is:");
        System.out.println("------------------");
        System.out.println(log);

      } catch (KubernetesClientException e) {
       System.out.println(e.getMessage());
      }
}
</code></pre>

<p>i get this Error reading service account token from: [/var/run/secrets/kubernetes.io/serviceaccount/token]. Ignoring.</p>

<p><strong>Where is the problem:</strong> The current type of your client configuration is incomplete, you are missing the client authentication settings/data part.</p>
<p>Please be aware, when you are running your code from outside the cluster
(this type of client configuration is called <strong>out-of-cluster client configuration</strong>) you need to specify explicitly a bare minimum for successful connection to Kubernetes control-plane from outside.</p>
<ol>
<li>Kubernetes Master URL</li>
<li>At least one method for <strong>user authentication</strong>, can be any of:</li>
</ol>
<ul>
<li>client certificates</li>
<li>bearer tokens</li>
<li>HTTP basic auth</li>
</ul>
<p><strong>You see the problem ?</strong> - you have specified none of these from the second condition for <code>&gt;&gt; user &lt;&lt;</code> authentication (this is a key word here: <code>user</code>)</p>
<p><strong>Right now</strong> Java Kubernetes client falls back into <strong>Service account</strong> based authentication strategy, thinking you are not human but robot (Pod running in context of Service Account).</p>
<p>Putting it technically, client is resolving now to the last resort option:</p>
<blockquote>
<p><a href="https://github.com/fabric8io/kubernetes-client/blob/b68aa7ea982a4eb2c90314716ea45e08600fd265/kubernetes-tests/pom.xml#L143" rel="nofollow noreferrer">KUBERNETES_AUTH_TRYSERVICEACCOUNT</a></p>
</blockquote>
<p>(<strong>4th</strong> on the list of fabric8io/kubernetes-client supported configuration option, check below)</p>
<p>which involves reading in service account token placed into the filesystem inside Pod's container at following path:</p>
<blockquote>
<p>/var/run/secrets/kubernetes.io/serviceaccount/token</p>
</blockquote>
<hr />
<p>Officially <a href="https://github.com/fabric8io/kubernetes-client#configuring-the-client" rel="nofollow noreferrer">fabric8io/kubernetes-client</a> java client supports the following ways of configuring the client:</p>
<blockquote>
<p>This will use settings from different sources in the following order
of priority:</p>
<ul>
<li>System properties</li>
<li>Environment variables</li>
<li>Kube config file</li>
<li>Service account token &amp; mounted CA certificate     &lt;== you client code tries this</li>
</ul>
<p>System properties are preferred over environment variables. The
following system properties &amp; environment variables can be used for
configuration</p>
</blockquote>
<p><strong>The easiest solution</strong> is to rely on <code>Kube config file</code> option to access cluster from outside, e.g.:</p>
<pre><code>public class KubeConfigFileClientExample {
  public static void main(String[] args) throws IOException, ApiException {

    // file path to your KubeConfig

    String kubeConfigPath = System.getenv(&quot;HOME&quot;) + &quot;/.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, null);
    for (V1Pod item : list.getItems()) {
      System.out.println(item.getMetadata().getName());
    }
  }
}
</code></pre>
<p>Full code sample can be found <a href="https://github.com/kubernetes-client/java/blob/master/examples/examples-release-12/src/main/java/io/kubernetes/client/examples/KubeConfigFileClientExample.java" rel="nofollow noreferrer">here</a>.</p>
