Learn how to deploy Spring Boot to Kubernetes using Docker Compose for local development and Minikube for a production-like cluster on your laptop. This updated deploy spring boot kubernetes tutorial covers Dockerfile best practices, Kubernetes manifests, and end-to-end testing.
Prerequisites: Basic Spring Boot and command-line familiarity. For the app itself, any Spring Boot REST project works — try the Java 21 virtual threads REST API or RAG chatbot.
Estimated time: 90 minutes. Difficulty: Intermediate.
Architecture Overview
What You Need
- Docker Desktop (or Docker Engine + Compose v2)
- Minikube — install guide
- kubectl — Kubernetes CLI
- A Spring Boot 3.x project with a health endpoint (
/actuator/healthrecommended) - 8 GB+ RAM allocated to Docker/Minikube
Step 1: Create or Use a Sample Spring Boot App
Add Spring Boot Actuator for health checks:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
management.endpoints.web.exposure.include=health,info
server.port=8080
Verify locally:
mvn spring-boot:run
curl http://localhost:8080/actuator/health

Step 2: Write a Multi-Stage Dockerfile
Create Dockerfile in the project root:
# Build stage
FROM eclipse-temurin:21-jdk-alpine AS build
WORKDIR /app
COPY pom.xml mvnw .mvn/ ./
RUN ./mvnw dependency:go-offline -B
COPY src ./src
RUN ./mvnw package -DskipTests -B
# Run stage
FROM eclipse-temurin:21-jre-alpine
WORKDIR /app
COPY --from=build /app/target/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]
Build and test the image:
docker build -t springboot-demo:1.0 .
docker run -p 8080:8080 springboot-demo:1.0

For Dockerfile fundamentals, see the earlier guide: Introduction to Dockerfile with Spring Boot.
Step 3: Local Dev with Docker Compose
Create docker-compose.yml for app + MySQL (optional):
services:
app:
build: .
ports:
- "8080:8080"
environment:
SPRING_DATASOURCE_URL: jdbc:mysql://db:3306/demo
SPRING_DATASOURCE_USERNAME: root
SPRING_DATASOURCE_PASSWORD: secret
depends_on:
- db
db:
image: mysql:8
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: demo
ports:
- "3306:3306"
docker compose up --build
See also: Docker Compose with Spring Boot and Dockerize Spring Boot with MySQL.

Step 4: Start Minikube Cluster
minikube start --cpus=4 --memory=8192 --driver=docker
kubectl cluster-info
minikube dashboard # optional — opens Kubernetes dashboard

Step 5: Build and Load the Container Image
Point your shell at Minikube’s Docker daemon so images build inside the cluster:
eval $(minikube docker-env)
docker build -t springboot-demo:1.0 .
Alternatively push to Docker Hub and reference the remote image in your Deployment.
Step 6: Create Kubernetes Deployment and Service
Create k8s/deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: springboot-demo
spec:
replicas: 2
selector:
matchLabels:
app: springboot-demo
template:
metadata:
labels:
app: springboot-demo
spec:
containers:
- name: app
image: springboot-demo:1.0
imagePullPolicy: Never
ports:
- containerPort: 8080
livenessProbe:
httpGet:
path: /actuator/health
port: 8080
initialDelaySeconds: 30
periodSeconds: 10
readinessProbe:
httpGet:
path: /actuator/health
port: 8080
initialDelaySeconds: 10
periodSeconds: 5
---
apiVersion: v1
kind: Service
metadata:
name: springboot-demo
spec:
type: NodePort
selector:
app: springboot-demo
ports:
- port: 8080
targetPort: 8080
nodePort: 30080
Apply the manifests:
kubectl apply -f k8s/deployment.yaml
kubectl get pods
kubectl get services

For YAML-only deployment patterns, compare with: Deploy Spring Boot using Deployment YAML.
Step 7: Test the Deployment
minikube service springboot-demo --url
# Or open NodePort directly:
curl http://$(minikube ip):30080/actuator/health
Expected response:
{"status":"UP"}

Frequently Asked Questions
Should I use Minikube or Docker Compose for Spring Boot?
Use Docker Compose for fast local dev with databases. Use Minikube when you need to test Kubernetes features — Deployments, Services, ConfigMaps, and scaling — before cloud deployment.
Why is my Pod stuck in ImagePullBackOff?
If you built locally with minikube docker-env, set imagePullPolicy: Never. If using Docker Hub, ensure the image name is correct and the cluster can pull it (check kubectl describe pod).
How do I deploy Spring Boot with MySQL on Kubernetes?
Add a MySQL Deployment + PersistentVolumeClaim, pass the JDBC URL via ConfigMap/Secret, and reference them in your app Deployment. See Deploy Spring Boot with MySQL to Minikube.
Can I deploy to Azure instead of Minikube?
Yes. Build and push to a container registry, then deploy to Azure Container Apps or AKS. Follow Deploy Spring Boot API to Azure.
How is this different from the 2021 Kubernetes beginner tutorial?
This 2026 guide consolidates Dockerfile, Compose, and Minikube into one updated path with Java 21, Actuator probes, and links to the new Spring Boot 3 tutorials. The 2019 beginner tutorial remains available for reference.
What about production Kubernetes?
Production adds ingress controllers, TLS, secrets management, CI/CD (GitHub Actions), and observability. Minikube validates manifests; cloud providers handle the control plane.
Next Steps
- Build a RAG Chatbot with Spring Boot — deploy AI services to K8s
- Java 21 Virtual Threads REST API — high-concurrency Spring Boot app
- Deploy Spring Boot + MySQL to Minikube
- Setup Kubernetes Locally — Step by Step
- Alkademy DevOps courses
Learn DevOps hands-on? Join Alkademy for live Docker, Kubernetes, and Spring Boot deployment workshops.