This project is a REST API built with Spring Boot to serve Premier League data from a JSON file. It allows users to query Clubs by Goals, Wins, Losses, Position and check all Fixtures. This README provides a step-by-step guide to build, containerize, and deploy the application using Maven, Docker, and Kubernetes (with Kind for local development). Instructions are provided for both Windows and macOS/Linux users.
Before starting, ensure you have the following installed:
- Java 17: For building the Spring Boot application.
- Maven: For dependency management and building the JAR.
- Docker: For containerizing the application.
- Kind: For running a local Kubernetes cluster.
- kubectl: For interacting with Kubernetes.
- curl or Postman: For testing API endpoints.
For Windows, use Chocolatey (a package manager) or manual installation:
-
Install Chocolatey (optional, run in Admin PowerShell):
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
-
Install Tools with Chocolatey:
choco install openjdk17 choco install maven choco install docker-desktop choco install kind choco install kubernetes-cli choco install curl
-
Manual Installation:
- Java 17: Download from Adoptium, set
JAVA_HOME
environment variable. - Maven: Download from Apache Maven, add
bin
toPATH
. - Docker: Install Docker Desktop, enable WSL 2 backend.
- Kind: Download from Kind releases, place in
C:\bin
. - kubectl: Download from Kubernetes releases, place in
C:\bin
.
- Java 17: Download from Adoptium, set
-
Set Up WSL 2 (recommended for Kind):
wsl --install wsl --update wsl --set-default-version 2
# Install Homebrew (macOS)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install tools
brew install openjdk@17
brew install maven
brew install docker
brew install kind
brew install kubectl
Pokedex-JSON/
├── src/
│ ├── main/
│ │ ├── java/org/example/
│ │ │ ├── actionSelector.java
│ │ │ ├── Club.java
│ │ │ ├── Fixture.java
│ │ │ ├── Main.java
│ │ │ ├── readClubs.java
│ │ │ ├── readFixtures.java
│ │ ├── resources/
│ │ │ ├── data.json
├── pom.xml
├── Dockerfile
├── premier-league-deployment.yaml
├── premier-league-service.yaml
├── README.md
data.json
: Contains Premier League data .Dockerfile
: Defines the Docker image build process.- Kubernetes manifests (
premier-league-deployment.yaml
,premier-league-service.yaml
): Define the Kubernetes resources.
The application is built using Maven to create an executable JAR file.
-
Build the JAR:
mvn clean package -DskipTests
- This compiles the code, runs the build, and generates
target/Premier-League-Application-1.0-SNAPSHOT.jar
. - The
-DskipTests
flag skips tests for faster builds (ensure tests pass if you have them).
- This compiles the code, runs the build, and generates
-
Run the Application Locally (Optional):
mvn spring-boot:run
- This starts the Spring Boot application on
http://localhost:8080
.
- This starts the Spring Boot application on
-
Test API Endpoints Locally: Use
curl
or a browser to test the API:# Get all Clubs curl http://localhost:8080/api/clubs # Get Clubs Sorted by Goals curl http://localhost:8080/api/clubs/goals # Get Clubs Sorted by Losses curl http://localhost:8080/api/clubs/losses
Windows Alternative (PowerShell):
Invoke-WebRequest -Uri http://localhost:8080/api/clubs
The application is packaged into a Docker container for deployment.
-
Build the Docker Image:
docker build -t premier-league-app .
-
This creates a Docker image named
premier-league-app
based on theDockerfile
. -
The
Dockerfile
uses a multi-stage build: Maven builds the JAR, and an Alpine JRE runs it.
-
-
Test the Docker Container:
docker run -p 8080:8080 premier-league-app
-
Maps port
8080
on the host to8080
in the container. -
Test the API at
http://localhost:8080/api/clubs
.
-
-
Push the Image to Docker Hub: To make the image available to Kubernetes, push it to Docker Hub:
# Log in to Docker Hub (create an account at https://hub.docker.com if needed) docker login # Tag the image with your Docker Hub username docker tag premier-league-app <your-dockerhub-username>/premier-league-app:latest # Push the image to Docker Hub docker push <your-dockerhub-username>/premier-league-app:latest
- Replace
<your-dockerhub-username>
with your Docker Hub username. - This makes the image accessible to Kubernetes clusters, including Kind.
- Replace
We use Kind to run a local Kubernetes cluster and deploy the API using Kubernetes manifests.
-
Create a Kind Cluster:
kind create cluster --name premier
- This starts a local Kubernetes cluster named
premier
.
- This starts a local Kubernetes cluster named
-
Verify the Cluster:
kubectl cluster-info --context kind-premier
- Ensures
kubectl
is connected to the Kind cluster.
- Ensures
If you prefer not to use Docker Hub, you can load the local premier-league-app
image into Kind:
kind load docker-image premier-league-app:latest --name premier
- This makes the image available to the Kind cluster without needing a registry. Skip this step if you pushed the image to Docker Hub.
The application is deployed using a Deployment
and exposed via a Service
. Optionally, an Ingress
can be used for HTTP access.
- Create the Deployment Manifest (
premier-league-deployment.yaml
):
apiVersion: apps/v1
kind: Deployment
metadata:
name: premier-league-app
namespace: default
labels:
app: premier-league-app
spec:
replicas: 2
selector:
matchLabels:
app: premier-league-app
template:
metadata:
labels:
app: premier-league-app
spec:
containers:
- name: premier-league-app
image: <your-dockerhub-username>/premier-league-app:latest
ports:
- containerPort: 8080
resources:
limits:
cpu: "500m"
memory: "512Mi"
requests:
cpu: "200m"
memory: "256Mi"
livenessProbe:
httpGet:
path: /api/clubs
port: 8080
initialDelaySeconds: 15
periodSeconds: 10
readinessProbe:
httpGet:
path: /api/clubs
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
- Important: Replace
<your-dockerhub-username>
with your Docker Hub username in theimage
field. If you used the local image withkind load docker-image
, useimage: premier-league-app:latest
instead.
-
Create the Service Manifest (
premier-league-service.yaml
):apiVersion: v1 kind: Service metadata: name: premier-league-app-service namespace: default spec: selector: app: premier-league-app ports: - protocol: TCP port: 80 targetPort: 8080 nodePort: 30080 type: NodePort
-
Apply the Manifests:
kubectl apply -f premier-league-deployment.yaml kubectl apply -f premier-league-service.yaml
-
Verify the Deployment:
kubectl get deployments kubectl get pods kubectl get services
- Ensure the
premier-league-app
Deployment has 2/2 pods ready. - Check that
premier-league-app-service
is running withtype: NodePort
.
- Ensure the
The NodePort
Service exposes the API on a high port (e.g., 30080
).
-
Get the Cluster IP:
kubectl get nodes -o wide
- Note the
INTERNAL-IP
of the Kind control plane node (e.g.,172.18.0.2
).
- Note the
-
Test the API:
curl http://<INTERNAL-IP>:30080/api/clubs curl http://<INTERNAL-IP>:30080/api/clubs/goals
Windows Alternative (PowerShell):
Invoke-WebRequest -Uri http://<INTERNAL-IP>:30080/api/clubs
- Replace
<INTERNAL-IP>
with the node’s IP.
- Replace
-
Port Forwarding (Alternative):
kubectl port-forward service/premier-league-app-service 8080:80
- Access the API at
http://localhost:8080/api/clubs
.
- Access the API at