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.
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.
Before you start, you need to ensure that you have:
- Install the recent version of AWS CDK v2 including AWS CDK prerequisites. I used the version 2.173.1
- Install kubectl to get access to the EKS cluster
- (Optional) Install eks-node-viewer to visualize EKS cluster nodes
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!
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"
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.
1/ Delete deployed resources:
2/ Destroy the deployed stacks. Review the changes proposed by CDK, and say "yes" to the CDK question:
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:
- Compute with EC2 managed instances deployed by Karpenter
- Networking with Amazon VPC CNI and Load Balancing with AWS Load Balancer Controller
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.