Featured Article

Spring Boot Kubernetes Tutorial: Deploy Containerized Apps Like a Pro

Kenneth Jul 13, 2026

Spring Boot, a popular Java-based framework, has revolutionized the way we build and deploy applications. Kubernetes, an open-source platform for automating deployment, scaling, and managing containerized applications, is a natural extension of Spring Boot's deployment capabilities. In this comprehensive tutorial, we'll explore how to deploy Spring Boot applications on Kubernetes.

Master Kubernetes Deployment for Your Spring Boot Microservices!
Master Kubernetes Deployment for Your Spring Boot Microservices!

By the end of this tutorial, you'll have a solid understanding of how to package your Spring Boot application, create a Kubernetes deployment, and manage your application's lifecycle. We'll use kubectl, the Kubernetes command-line interface, for interacting with our Kubernetes cluster.

a diagram with the words how to learn kubernets on it and an image of
a diagram with the words how to learn kubernets on it and an image of

Packaging Your Spring Boot Application

Before deploying to Kubernetes, you need to package your Spring Boot application as a executable jar. This can be done using the 'spring-boot-maven-plugin' or 'spring-boot-gradle-plugin'.

How To Work With Apache Kafka In Spring Boot?
How To Work With Apache Kafka In Spring Boot?

Navigate to your project root directory and create an executable jar by running `./mvnw spring-boot:repackage` (Maven) or `./gradlew bootJar` (Gradle). This will generate a jar file in the 'target' directory.

Building the Docker Image

Spring Boot cheatsheet - Masterspringboot
Spring Boot cheatsheet - Masterspringboot

Next, we'll build a Docker image using the packed Spring Boot jar. In your project root directory, create a Dockerfile with the following content:

FROM openjdk:8-jdk-alpine
ADD target/your-application.jar app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

Replace 'your-application.jar' with the name of your jar file. Then, build the Docker image by running `docker build -t your-application .`

Pushing the Docker Image

Spring Boot Docker- How To Deploy Spring Boot Application In Docker?
Spring Boot Docker- How To Deploy Spring Boot Application In Docker?

Tag your Docker image with a registry like Docker Hub for easy access. Replace 'your-username' with your Docker Hub username:

docker tag your-application:latest your-username/your-application:latest
docker push your-username/your-application:latest

Deploying to Kubernetes

Now that our application is in a Docker image, we can deploy it to Kubernetes. We'll use a deployment object for this.

Spring Boot With JSP and Spring MVC | Java Inspires
Spring Boot With JSP and Spring MVC | Java Inspires

Create a file named 'deployment.yaml' with the following content:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: your-application-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: your-application
  template:
    metadata:
      labels:
        app: your-application
    spec:
      containers:
      - name: your-application
        image: your-username/your-application:latest

Applying the Deployment

Top 6 Online Courses to Learn Kubernetes in 2025 - Best of Lot
Top 6 Online Courses to Learn Kubernetes in 2025 - Best of Lot
Features of Spring Boot
Features of Spring Boot
How To Deploy Spring Boot Application To Docker?
How To Deploy Spring Boot Application To Docker?
Top 10 Advanced Courses for Full Stack Java Developers
Top 10 Advanced Courses for Full Stack Java Developers
Deploy Java Spring Boot Applications to AWS, Azure, GCP with Docker and Kubernetes
Deploy Java Spring Boot Applications to AWS, Azure, GCP with Docker and Kubernetes
the rules for kuberites in plain english are shown on a white background with blue text
the rules for kuberites in plain english are shown on a white background with blue text
Java + Spring Boot + Microservices Example - Step by Step Guide
Java + Spring Boot + Microservices Example - Step by Step Guide
Code Quality - What is Refactoring?
Code Quality - What is Refactoring?
Kotlin Application Deployment with Docker and Kubernetes
Kotlin Application Deployment with Docker and Kubernetes

Now, let's apply this deployment configuration to our Kubernetes cluster using kubectl:

kubectl apply -f deployment.yaml

Exposing the Application

To access our application, we need to expose it as a service. Create a new file named 'service.yaml' with the following content:

apiVersion: v1
kind: Service
metadata:
  name: your-application-service
spec:
  selector:
    app: your-application
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
  type: LoadBalancer

Then apply this configuration using kubectl:

kubectl apply -f service.yaml

After a few moments, your Spring Boot application will be up and running on Kubernetes. To verify, use `kubectl get pods` to list your running pods, or access your application using the external IP provided by the LoadBalancer service.

With this, you're ready to start scaling, managing, and updating your Spring Boot application using Kubernetes. Happy coding!