Running a Amazon Corretto based Java app on an Amazon EKS cluster powered by AWS Graviton2 based EC2 worker nodes

Mani
5 min readAug 25, 2020

We just published a blog on Amazon Elastic Kubernetes Service (EKS) being generally available on the Graviton2 processors by Michael Hausenblas , using Graviton2 based instances for running EKS worker nodes

Last year, I published a short blog on running a Corretto based Java application on an Amazon ECS cluster running A1 instances (A1 instances were the first EC2 instances powered by AWS Graviton Processors). I was inspired today by this announcement, to run the same Java application (with the Java run-time from Amazon Corretto) on Amazon EKS and powered by Graviton2 processors. My main aim was pretty selfish, to get myself familiar with the steps and hopefully it helps other developers.

The EC2 instances are powered by AWS Graviton2 processors that are built utilizing 64-bit Arm Neoverse cores and custom silicon designed by AWS. AWS Graviton2 processors deliver a major leap in performance and capabilities over first-generation AWS Graviton processors, with 7x performance, 4x the number of compute cores, 2x larger caches, and 5x faster memory. AWS Graviton2 processors feature always-on 256-bit DRAM encryption and 50% faster per core encryption performance compared to the first-generation AWS Graviton processors.

Of course, you should do your own due diligence based on your workload — including whether the software, libraries are compatible on ARM based instances and run your own benchmarks with a POC .. Also, please have a look at some important considerations while considering Graviton2 based instances with EKS.

In social media, there has been a buzz amongst the early adopters of Graviton2 instances ..

from https://twitter.com/lizthegrey/status/1296837123195260928

from https://twitter.com/toxic/status/1296933303598030849

A sample price comparison of EC2 instances powered by Graviton2, Intel and AMD in the US N. Virginia region using the AWS simple monthly calculator is shown below. Make sure to check the latest prices on the AWS EC2 web page — https://aws.amazon.com/ec2/instance-types/

a sample representation of monthly costs of various processor types ..

and also more importantly (to me) — “Amazon EC2 M6g, C6g and R6g instances powered by AWS Graviton2 processors are now available in Asia Pacific (Mumbai, Singapore, Sydney) regions” !!

courtesy — https://textcraft.net/ ;-)

This short blog will reuse the code from my previous blog to run the same Java application on an EKS cluster with Graviton2 based worker nodes in AWS Mumbai region.

As per the documentation:

Amazon EC2 M6g instances are powered by Arm-based AWS Graviton2 processors. They deliver up to 40% better price/performance over current generation M5 instances and offer a balance of compute, memory, and networking resources for a broad set of workloads.

The deployment steps that I followed:

Create an Amazon EKS cluster with ARM based Graviton6 instances:

We will create an EKS cluster with m6g based EC2 worker nodes.

Amazon EC2 M6g instances are powered by Arm-based AWS Graviton2 processors. They deliver up to 40% better price/performance over current generation M5 instances and offer a balance of compute, memory, and networking resources for a broad set of workloads.

Note: Make sure you are running the latest eksctl binaries — https://eksctl.io/usage/arm-support/

eks-graviton2-cluster.yaml

apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: eks-cluster-arm
region: ap-south-1
managedNodeGroups:
- name: mng-arm0
instanceType: m6g.medium
desiredCapacity: 3

Create the cluster:

eksctl create cluster -f eks-graviton2-cluster.yaml

Check the nodes, after the cluster gets created:

$ kubectl get nodes -lbeta.kubernetes.io/arch=arm64
NAME STATUS ROLES AGE VERSION
ip-192-168-26-119.ap-south-1.compute.internal Ready <none> 4h6m v1.17.9-eks-4c6976
ip-192-168-38-69.ap-south-1.compute.internal Ready <none> 4h6m v1.17.9-eks-4c6976
ip-192-168-64-201.ap-south-1.compute.internal Ready <none> 4h6m v1.17.9-eks-4c6976

Build the Java app and push it to Amazon ECR

For building the app, I used an EC2 instance which was powered by Graviton2 and installed Java, a few additional tools including the AWS CLI to build the app and push the image to Amazon ECR.

# follow https://docs.aws.amazon.com/AmazonECS/latest/developerguide/docker-basics.html to install docker on Amazon EC2$ sudo amazon-linux-extras enable corretto8
$ sudo yum install java-1.8.0-amazon-corretto
$ java -version
openjdk version "1.8.0_262"
OpenJDK Runtime Environment Corretto-8.262.10.1 (build 1.8.0_262-b10)
OpenJDK 64-Bit Server VM Corretto-8.262.10.1 (build 25.262-b10, mixed mode)
#clone the repogit clone https://github.com/cmanikandan/aws-ecs-a1-corretto
cd aws-ecs-a1-corretto

I made some minor changes to src/main/java/hello/Application.java to reflect that it was running inside Amazon EKS ;-)

public class Application {@RequestMapping("/")
public String home() {
String str = "Hello, I'm running inside Amazon EKS on AWS Graviton2 processors <br> The Java Runtime version is " + System.getProperty("java.runtime.version") + " from "+ System.getProperty("java.vm.name") + " and my Java home is " + System.getProperty("java.home") + "\n <br>";
str = str.concat("Operating System details: ").concat(System.getProperty("os.arch")).concat(" ").concat(System.getProperty("os.name")).concat(" ").concat(System.getProperty("os.version")).concat("\n <br>");
str = str.concat("Note: This is for demonstration purposes ONLY !! \n");
return str;

}

Build the app:

./gradlew build

Create an repo on Amazon ECR - called corretto-eks-graviton2 and push the image.

#setup AWS CLI
aws configure
aws ecr get-login-password — region ap-south-1 | docker login — username AWS — password-stdin xxx.dkr.ecr.ap-south-1.amazonaws.comdocker build -t corretto-eks-graviton2 .docker tag corretto-eks-graviton2:latest xxx.dkr.ecr.ap-south-1.amazonaws.com/corretto-eks-graviton2:latestdocker push xxx.dkr.ecr.ap-south-1.amazonaws.com/corretto-eks-graviton2:latest

Create a simple Kubernetes service with a classic load balancer, from the container image that we have pushed to ECR:

deployapp.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
name: hellojava
spec:
replicas: 3
selector:
matchLabels:
app: hellojava
template:
metadata:
labels:
app: hellojava
spec:
containers:
- name: main
image: xxx.dkr.ecr.ap-south-1.amazonaws.com/corretto-eks-graviton2:latest
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: hellojava
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 8080
selector:
app: hellojava

Deploy the app:

$ kubectl apply -f deployapp.yaml$ kubectl get pods
NAME READY STATUS RESTARTS AGE
hellojava-675bc96f7c-j9t5t 1/1 Running 0 17m
hellojava-675bc96f7c-sc94r 1/1 Running 0 17m
hellojava-675bc96f7c-z7nzm 1/1 Running 0 17m
$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hellojava LoadBalancer 10.100.117.75 xxxx-5158381.ap-south-1.elb.amazonaws.com 80:31557/TCP 17m
kubernetes ClusterIP 10.100.0.1 <none> 443/TCP 7h55m

Access the Load balancer URL !!

Our hello world app ..

Note: Make sure to clean up the resources, once your done with this proof of concept ..

That’s it !!

This was a quick intro for folks to create an Amazon EKS cluster powered by Graviton2 based EC2 worker nodes and to deploy an simple Amazon Corretto based Java app on the Kubernetes cluster.

Hope this was useful.

--

--

Mani

Principal Solutions Architect at AWS India, and I blog/post about interesting stuff that I am curious about and which is relevant to developers & customers.