Skip to content

Guide to deploying a Spring boot application to EKS

Notifications You must be signed in to change notification settings

spjenk/HelloSpringEKS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hello

Example project deploying a Spring Boot applications to AWS EKS

Prerequisities

  • Java 8 / maven etc
  • Docker
  • Kubectl
  • helm

Set-up

  • Created application via start.spring.io (Web, DevTools)
  • Added Hello Rest Controller
  • Run locally
mvn spring-boot:run

Add Docker

  • Added dockerfile-maven-plugin and maven-dependency-plugin to pom file
  • Created docker file
  • build
mvn install
  • checked BOOT-INF AND META-INF now exsit under target/dependency/
  • build docker container
 docker build -t spjenk/hello .
  • run docker container
docker container run --name hello -p 8080:8080 -d spjenk/hello
curl http://localhost:8080/hello
  • push to dockerhub
docker push spjenk/hello:latest

Add Kubernetes

We are going to run Kubernetes locally first and deploy to EKS in the next step

  • Ensure Kubernetes is enabled in Docker (docker > settings > Kubernetes > Enable)
  • switch kube context to desktop mode
kubectl config use-context docker-for-desktop
  • Create skaffold helm chart
helm create chart
  • Updated chart 'values' YAMl file with the following
image:
  repository: spjenk/hello
  tag: latest
  pullPolicy: IfNotPresent
service:
  type: LoadBalancer
  port: 8080
  • deploy
helm install --name hello chart
  • get the external ip address (may take a minute)
kubectl get svc
  • check the pods are running (number should match replicas value in values.yaml)
kubectl get pods
  • Remove the application once finished testing (e.g. localhosst:8080/hello)
helm delete --purge hello

Deploy to AWS EKS

Now we will deploy the application to the cloud. Use the templates in tutorial EKS getting started to create a VPC for our EKS application. We will need the following details to continue:

Security Group: sg-xxxx
VpcId: vpc-xxxx
SubnetIds: subnet-xxx1, subnet-xxx2, subnet-xxx3

Create the EKS Cluster using the values above

aws eks --region ap-southeast-2 create-cluster --name dev --role-arn arn:aws:iam::xxx:role/eksServiceRole --resources-vpc-config subnetIds=subnet-xxx,subnet-xxx,subnet-xxx,securityGroupIds=sg-xxx

Once the Cluster is active, add it the the kubeconfig

aws eks update-kubeconfig --name dev

Check the new cluster is now set as the default

>kubectl config get-contexts
CURRENT   NAME                                                  CLUSTER                                               AUTHINFO                                              NAMESPACE
*         arn:aws:eks:ap-southeast-2:xxx:cluster/dev   arn:aws:eks:ap-southeast-2:xxx:cluster/dev   arn:aws:eks:ap-southeast-2:xxx:cluster/dev
          docker-for-desktop

Create worker nodes (refer to EKS getting started) from cloud formation template

https://amazon-eks.s3-us-west-2.amazonaws.com/cloudformation/2019-01-09/amazon-eks-nodegroup.yaml

Join worker nodes to the cluster (note: update role arn with output from cloud formation creation above)

kubectl apply -f aws-auth-cm.yaml

Wait until the nodes are ready

kubectl get nodes

Install helm

kubectl -n kube-system create sa tiller
kubectl create clusterrolebinding tiller --clusterrole cluster-admin --serviceaccount=kube-system:tiller
helm init --service-account tiller

Deploy

helm install --name hello chart

Find the external url

kubectl get svc -o wide

Cost saving tips

  • Scale horizontally (i.e. use small instance sizes)
  • If you know the application will not be used at certain times (e.g. outside working hours) then update the auto scaling group for the worker nodes to min: 0, desired: 0 during those times

References

create-your-first-helm-chart

EKS getting started

About

Guide to deploying a Spring boot application to EKS

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published