Github Link https://github.com/getramki/Deploy-JavaApp-On-EKS.git

This repo contains a Sample Spring Boot Java App with the dockerfile which uses Amazon Corretto 17 as base image and manifestes for creating an Amazon EKS cluster and deploying the sample app to the cluster as a container and exposing it with a service and classic load balancer.

Prerequisites

Docker, AWS Account and IAM user with necessary permissions for creating EKS Cluster, aws cli, configure IAM user with necessary programmatic permissions, eksctl cli, kubectl Please install and configure above before going further

  • You can incur charges in your AWS Account by following this steps below
  • The code will deploy in us-west-2 region, change it where ever necessary if deploying in another region

After downloading the repo in the terminal CD to repo directory and follow the steps for

  1. Building a Docker Image for a Java App and Pushing it to Amazon ECR.
  2. Creating an Amazon EKS cluster with eksctl
  3. Deploying the sample app to the EKS cluster.

Steps for Building a Docker Image and Pushing it to Amazon ECR

  • Change directory to sample
cd sample
  • Run docker daemon
sudo dockerd 
  • Build an image
docker build --tag sample . 
  • View local images
docker images
  • docker build build stage
docker build -t sample-build --target build . 
  • docker build production stage
docker build -t sample-production --target production . 
  • Get ECR Login and pass it to docker
aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin Replace-With-AWS-Account-ID.dkr.ecr.us-west-2.amazonaws.com
  • Create ECR repo
aws ecr create-repository --repository-name sample-repo --image-scanning-configuration scanOnPush=true --region us-west-2
  • Tag the image
docker tag sample-production:latest Replace-With-AWS-Account-ID.dkr.ecr.us-west-2.amazonaws.com/sample-repo
  • Push the Image to ECR Repo
docker push Replace-With-AWS-Account-ID.dkr.ecr.us-west-2.amazonaws.com/sample-repo

Create EKS Cluser

Create an Amazon EKS cluster in us-west-2 region with 2 t3.micro instances Creation of EKS cluster can take up to 20 minutes

eksctl create cluster -f devcluster-addons-us-west-2.yaml

Deploy Image to EKS Cluster

Update Image URL in deployment.yaml file Replace-With-AWS-Account-ID

  • Deploy Java Sample-App
kubectl apply -f deployment.yaml
  • Deploy Java Sample-App Service
kubectl apply -f service.yaml
kubectl apply -f ingress.yaml
  • Get Deployments
kubectl get deployment sample-app
kubectl get deployments
kubectl get service sample-app -o wide
kubectl get pods -n default

Delete Resources

  • Delete Deployments
kubectl delete deployment sample-app
  • Delete services
kubectl delete service sample-app
  • Delete ingress if you have created it
kubectl delete ingress sample-app
  • Delete Amazon EKS Cluster
eksctl delete cluster -f devcluster-addons-us-west-2.yaml
Share This