Prerequisite:
What is EKS?
EKS, or Amazon Elastic Kubernetes Service, is a managed Kubernetes service offered by Amazon Web Services (AWS). It allows users to run Kubernetes without needing to install and operate their own Kubernetes control plane or nodes. EKS simplifies the process of running Kubernetes on AWS, allowing developers to focus on deploying and managing applications rather than maintaining the underlying infrastructure. In simpler terms, it’s a tool that helps you efficiently run and manage your software applications in a flexible and scalable way. EKS takes care of many technical details, you don’t have to worry too much about the complicated details — it’s like having someone else take care of the hard work so you can focus on using your programs
In this blog we will focus on how we can deploy simple spring boot application on Amazon EKS (Elastic Kubernetes Service)
STEP 1: Create a spring boot application
4.0.0 org.springframework.boot spring-boot-starter-parent 3.2.5 dineshremje com.dinesh Dinesh Remje Service 1.0.0 jar org.springframework.boot spring-boot-starter org.springframework.boot spring-boot-starter-tomcat org.springframework.boot spring-boot-starter-web org.springdoc springdoc-openapi-starter-webmvc-ui 2.0.2 org.projectlombok lombok provided org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-maven-plugin
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import io.swagger.v3.oas.annotations.Operation; @RestController @RequestMapping("/v1") public class DineshRemjeController { @Operation(summary = "This api is mainly to test the app for printing Welcome Message") @GetMapping("/hello") @ResponseBody public String printHello() { return "Welcome to First Step of Application Deployment on EKS"; } }
FROM openjdk:17
ADD target/dineshremje-1.0.0.jar dinesh-eks.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","dinesh-eks.jar"]
mvn clean install
STEP 2: Create EKS Cluster
eksctl create cluster --name dinesh-cluster --version 1.28 --nodes=1 --node-type=t2.small --region ap-south-1The above command helps to create cluster in AWS account for a particular region with 1 node with EC2 instance of type t2.small, the version here denotes the kubernetes version.
aws eks update-kubeconfig --region ap-south-1 --name dinesh-cluster
kubectl get svc
Output in command prompt or GIT bash would be shown as follow
STEP 3: Deployment of our application on EKS nodes
Command to applyapiVersion: apps/v1 kind: Deployment metadata: name: dineshapp spec: replicas: 3 selector: matchLabels: app: dineshapp template: metadata: labels: app: dineshapp spec: containers: - name: dineshapp image: {account_id}.dkr.ecr.ap-south-1.amazonaws.com/dinesh-eks:latest ports: - containerPort: 8080 --- apiVersion: v1 kind: Service metadata: name: dineshapp-service spec: selector: app: dineshapp ports: - protocol: TCP port: 80 targetPort: 8080 type: LoadBalancer
kubectl apply -f dineshk8s.yaml
kubectl get svc
kubectl get deployment
kubectl get pods
Output for kubectl get svc is shown above, for other two commands output are as follow
kubectl get pods
kubectl get deployment
Note: If pods and deployment command shows the status as Running that means your application has been deployed successfully and would be accessible through the
external url obtained through svc command. You can invoke /v1/hello api using external host in browser