Set or Modify authentication mode of EKS cluster to API_AND_CONFIG_MAP

56 Views Asked by At

I am new to AWS CDK. I am trying to create EKS cluster on AWS using this java code:

Cluster.Builder.create(this, "eks")
    .vpc(vpc)
    .version(KubernetesVersion.V1_24)
    .vpcSubnets(List.of(SubnetSelection.builder().subnetType(SubnetType.PRIVATE_ISOLATED).build()))
    .endpointAccess(EndpointAccess.PRIVATE)
    .clusterName(clusterName)
    .kubectlLayer(new KubectlLayer(this, kubectLayerName))
    .defaultCapacity(0)
    .mastersRole(clusterAdmin)
    .placeClusterHandlerInVpc(true)
    .clusterHandlerEnvironment(Map.of("AWS_STS_REGIONAL_ENDPOINTS", "regional"))
    .kubectlEnvironment(Map.of("AWS_STS_REGIONAL_ENDPOINTS", "regional"))
    .build();

It works successfully and creates the cluster. But it sets the authentication mode by default to CONFIG_MAP. I want to change it to API_AND_CONFIG_MAP.

The issue is already open since 3 months on Github here. The development is ongoing and it might take time. But, we require the solution sooner if possible, so I am asking it here. Can anyone help me with any alternate way to set authentication mode?

One solution was suggested on github (which wasn't working for him either, but still I tried) :

if (cluster.getNode().getDefaultChild() instanceof CfnCluster cfnCluster) {
  cfnCluster.setAccessConfig(CfnCluster.AccessConfigProperty.builder()
      .authenticationMode("API_AND_CONFIG_MAP")
      .build());
}

This didn't work.

I can use CfnCluster instead of eks.Cluster to create cluster, because CfnCluster has a way to set authentication mode. But, I am not sure how to set all of the above properties for cluster like vpc, subnets, etc. in CfnCluster.

0

There are 0 best solutions below