Guide to deploying a Spring boot application to EKS
Last updated Dec 29, 2024
12
Stars
9
Forks
0
Issues
0
Stars/day
Attention Score
3
Language breakdown
Smarty 46.3%
Java 41.6%
Dockerfile 12.1%
▸ Files
click to expand
README
Hello
Example project deploying a Spring Boot applications to AWS EKSPrerequisities
- 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🔗 More in this category