title: How to connect to DigitalOcean Kubernetes cluster from Java?
body: <p>I have a Kubernetes cluster on DigitalOcean, and I try to list the pods in it using Kubernetes Java API.</p>
  
  <pre><code>String kubeConfigPath = "~/.kube/config";
  
  KubeConfig config = KubeConfig.loadKubeConfig(new FileReader(kubeConfigPath));
  
  ApiClient client = ClientBuilder
          .kubeconfig(config)
          .build();
  
  Configuration.setDefaultApiClient(client);
  
  CoreV1Api api = new CoreV1Api();
  
  V1PodList list = api.listNamespacedPod("default", true, null,
          null, null, null,
          null, null, null,
          null
  );
  
  for (V1Pod item : list.getItems()) {
      System.out.println(item.getMetadata().getName());
  }
  </code></pre>
  
  <p>But when I run it, I get the following error</p>
  
  <pre><code>Exception in thread "main" io.kubernetes.client.ApiException: Forbidden
      at io.kubernetes.client.ApiClient.handleResponse(ApiClient.java:886)
      at io.kubernetes.client.ApiClient.execute(ApiClient.java:802)
      at io.kubernetes.client.apis.CoreV1Api.listNamespacedPodWithHttpInfo(CoreV1Api.java:16949)
      at io.kubernetes.client.apis.CoreV1Api.listNamespacedPod(CoreV1Api.java:16926)
      at com.workfront.k8s.KubeConfigFileClientExample.main(KubeConfigFileClientExample.java:30)
  </code></pre>
  
  <p>When I use minikube, it works fine.</p>