Search code examples
kubernetesaws-sdkfabric8

How to configure KubernetesClient to connect to AWS EKS ckluster


I'm trying to use io.fabric8.kubernetes.client.KubernetesClient to connect to my AWS EKS cluster but I'm having no luck as follows:

  Cluster cluster =
      EKSClient.describeCluster(DescribeClusterRequest.builder().name(clusterName).build())
          .cluster();

  final io.fabric8.kubernetes.client.Config kubeConfig =
      new ConfigBuilder()
          .withMasterUrl(cluster.endpoint())
          .withTrustCerts(true)
          .withRequestTimeout(10_000)
          .build();

  kubernetesClient = new DefaultKubernetesClient(kubeConfig);

The connection just times out so I'm sure I'm missing something. I can reach the AWS cluster with all the AWS SDK tools but those don't provide everything I need.

Any ideas/suggestions?


Solution

  • Found this question when also was looking for ways to connect to EKS. Will post my solution in case someone finds it useful.
    In my case I first obtain the token with encoded IAM role via aws eks get-token --cluster-name=my-cluster command and then use it in the ConfigBuilder:

    new DefaultKubernetesClient(
               new ConfigBuilder().withMasterUrl(clusterEndPoint)
                          .withOauthToken(retrievedToken).withTrustCerts(true).build());