AWS Logo
Menu
Keys included Kubernetes cluster with EKS Auto Mode and CDK with Java

Keys included Kubernetes cluster with EKS Auto Mode and CDK with Java

Learn how to deploy Amazon EKS Auto Mode clusters using AWS CDK with Java. Automate setup for a fully functional Kubernetes environment in minutes.

Yuriy Bezsonov
Amazon Employee
Published Dec 18, 2024
Disclaimer: Opinions are my own. The solution and source code below are provided for informational purposes only, without any guarantees or liability.
Amazon Elastic Kubernetes Service (EKS) is a fully managed Kubernetes service that enables you to run Kubernetes seamlessly in both AWS Cloud and on-premises data centers. Just a few days before AWS re:Invent 2024, a new, exciting feature was released - Amazon EKS Auto Mode. This feature gives you a possibility to have a fully functional EKS cluster in a matter of minutes, with all necessary components included. There are several methods of deploying an EKS cluster. You can find some of them in the documentation or in the launch blog, but today I will use another one - deploying with AWS Cloud Development Kit (CDK) in Java. You can use a similar approach if you use other programming languages with AWS CDK.

Overview of a solution

The CDK L2 eks.Cluster construct doesn’t support Auto Mode yet, so I will use the more low-level L1 eks.CfnCluster construct, which already has support for Amazon EKS Auto Mode.

Prerequisites

Before you start, you need to ensure that you have:

Walkthrough

Creating a Java CDK application

1/ Use the instructions below or documentation and create the CDK application:
2/ Create the implementation of the src/main/java/com/myorg/EksAutoModeStack.java class. The content of the file below includes comments for the most important parts of the code:
3/ Before you build the project, open the src/main/java/com/myorg/EksAutoModeStack.java file and replace the placeholder with your IAM Role ARN:
4/ Build the CDK project:
5/ Deploy the CDK project to your AWS account:
6/ Review the changes which proposed by CDK, say “yes” to the CDK question, and in 10-15 minutes you will have a ready-to-use Amazon EKS cluster!
eks-auto-mode-cluster
Amazon EKS Auto Mode cluster

Deploying workloads

1/ Get access to the EKS cluster:
If you have problems accessing the EKS cluster, you can go to EKS cluster console and add your role to "Access/IAM access entries" with "AmazonEKSClusterAdminPolicy"
2/ Get the EKS cluster nodes:
3/ You should receive “No resources found"
eks-node-viewer-initial
Initial state of the cluster
4/ Deploy a sample load balancer workload to the EKS Auto Mode cluster using this instructions or the code snippet below:
5/ Check that all resources have deployed properly. It might take 3-5 minutes to deploy the Application Load Balancer (ALB):
Now you have an up and running EKS cluster and can play the game using the ALB address above. You can also scale the number of replicas in the deployment to 10 and back to zero to see how EKS cluster nodes are created and destroyed.
eks-node-viewer-5-pods
The cluster after deployment
eks-node-viewer-10-pods
The cluster after scaling to 10 pods
eks-node-viewer-0-pods
The cluster after scaling to zero

Cleaning up

1/ Delete deployed resources:
2/ Destroy the deployed stacks. Review the changes proposed by CDK, and say "yes" to the CDK question:

Conclusion

In this blog post, I demonstrated how to deploy an Amazon EKS cluster in Auto Mode using AWS CDK with Java. This setup not only gives you the ability to automate EKS cluster deployment, but also delivers a ready-to-use EKS cluster with:
  • Managed Kubernetes Control Plane
  • Managed Kubernetes Data Plane with Amazon EKS Auto Node Managed Capabilities including:
Developers can now deploy their applications to the EKS cluster immediately after its creation. Let's go build!
 

Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.

Comments