How to Deploy Spring Boot Application in Kubernetes ?
Last Updated :
23 Jul, 2025
The Spring Boot framework provides an assortment of pre-configured templates and tools to make the development of Java-based applications simpler. With little configuration, it enables developers to quickly design production-ready, stand-alone apps.
Kubernetes, commonly referred to as K8s, is an open-source platform meant to automate the deployment, scaling, and management of containerized applications. It provides an extensive architecture for operating microservices, providing features such as load balancing, service discovery, automated rollouts, and self-healing. Developers can take advantage of these capabilities to make sure their Spring Boot apps are scalable, feasible, and solid by deploying them to Kubernetes.
Step by Step to Deploy Spring Boot Application in Kubernetes
Step 1: Create the GitHub repository.
Step 2: Here is my spring boot GitHub repository.

Step 3: Create the manifest file for the Kubernetes. Here i have create the manifest file for the spring boot application.

Here is the complete manifest file for the spring application and connected to the mogo database.
apiVersion: apps/v1
kind: Deployment
metadata:
name: springapp
labels:
app: springapp
spec:
replicas: 1
selector:
matchLabels:
app: springapp
template:
metadata:
labels:
app: springapp
spec:
containers:
- name: springcon
image: dockerhandson/spring-app-mongo:1
ports:
- containerPort: 8080
resources:
requests:
cpu: 200m
memory: 256Mi
limits:
cpu: 300m
memory: 512Mi
env:
- name: MONGO_DB_HOSTNAME
value: mongosvc
- name: MONGO_DB_USERNAME
value: devdb
- name: MONGO_DB_PASSWORD
value: devdb@123
---
apiVersion: v1
kind: Service
metadata:
name: springsvc
spec:
type: NodePort
selector:
app: springapp
ports:
- port: 80
targetPort: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongo
spec:
replicas: 1
selector:
matchLabels:
app: mongo
template:
metadata:
labels:
app: mongo
spec:
containers:
- name: mongocon
image: mongo
ports:
- containerPort: 27017
resources:
requests:
cpu: 200m
memory: 256Mi
limits:
cpu: 300m
memory: 512Mi
env:
- name: MONGO_INITDB_ROOT_USERNAME
value: devdb
- name: MONGO_INITDB_ROOT_PASSWORD
value: devdb@123
---
apiVersion: v1
kind: Service
metadata:
name: mongosvc
spec:
type: ClusterIP
selector:
app: mongo
ports:
- port: 27017
targetPort: 27017
Deployment Resource for Spring Boot Application:
- apiVersion: apps/v1: Specifies the API version used to create this resource.
- kind: Deployment: Defines the resource type as a Deployment, which manages the deployment of applications.
- metadata: Contains metadata about the deployment, including the name (springapp) and labels.
- spec: Describes the desired state of the Deployment.
- replicas: 1: Specifies that one replica (or instance) of the application should run.
- selector: Defines how to identify the Pods managed by this Deployment, matching labels.
- template: Provides the Pod template used to create Pods.
- metadata: Contains metadata for the Pods, including labels.
- spec: Describes the Pod's specification.
- containers: Lists the containers that make up the Pod.
- name: springcon: Names the container.
- image: dockerhandson/spring-app-mongo:1: Specifies the container image to use.
- ports: Lists the ports exposed by the container.
- containerPort: 8080: Exposes port 8080.
- resources: Specifies resource requests and limits.
- requests: Minimum resources required.
- cpu: 200m: 200 milliCPU (0.2 CPU).
- memory: 256Mi: 256 MiB of memory.
- limits: Maximum resources allowed.
- cpu: 300m: 300 milliCPU (0.3 CPU).
- memory: 512Mi: 512 MiB of memory.
- env: Sets environment variables for the container.
- MONGO_DB_HOSTNAME: Hostname of the MongoDB service (mongosvc).
- MONGO_DB_USERNAME: Username for MongoDB (devdb).
- MONGO_DB_PASSWORD: Password for MongoDB (devdb@123).
Service Resource for Spring Boot Application:
- apiVersion: v1: Specifies the API version.
- kind: Service: Defines the resource type as a Service.
- metadata: Contains metadata about the service, including the name (springsvc).
- spec: Describes the desired state of the Service.
- type: NodePort: Exposes the service on each node's IP at a static port.
- selector: Defines how to identify the Pods targeted by this Service, matching labels.
- ports: Lists the ports that the Service exposes.
- port: 80: The port on the Service.
- targetPort: 8080: The port on the Pod to forward traffic to.
Deployment Resource for MongoDB:
- apiVersion: apps/v1: Specifies the API version.
- kind: Deployment: Defines the resource type as a Deployment.
- metadata: Contains metadata about the deployment, including the name (mongo).
- spec: Describes the desired state of the Deployment.
- replicas: 1: Specifies that one replica (or instance) of the MongoDB container should run.
- selector: Defines how to identify the Pods managed by this Deployment, matching labels.
- template: Provides the Pod template used to create Pods.
- metadata: Contains metadata for the Pods, including labels.
- spec: Describes the Pod's specification.
- containers: Lists the containers that make up the Pod.
- name: mongocon: Names the container.
- image: mongo: Specifies the container image to use.
- ports: Lists the ports exposed by the container.
- containerPort: 27017: Exposes port 27017.
- resources: Specifies resource requests and limits.
- requests: Minimum resources required.
- cpu: 200m: 200 milliCPU (0.2 CPU).
- memory: 256Mi: 256 MiB of memory.
- limits: Maximum resources allowed.
- cpu: 300m: 300 milliCPU (0.3 CPU).
- memory: 512Mi: 512 MiB of memory.
- env: Sets environment variables for the container.
- MONGO_INITDB_ROOT_USERNAME: Root username for MongoDB (devdb).
- MONGO_INITDB_ROOT_PASSWORD: Root password for MongoDB (devdb@123).
Service Resource for MongoDB:
- apiVersion: v1: Specifies the API version.
- kind: Service: Defines the resource type as a Service.
- metadata: Contains metadata about the service, including the name (mongosvc).
- spec: Describes the desired state of the Service.
- type: ClusterIP: Exposes the service on a cluster-internal IP. Only accessible within the cluster.
- selector: Defines how to identify the Pods targeted by this Service, matching labels.
- ports: Lists the ports that the Service exposes.
- port: 27017: The port on the Service.
- targetPort: 27017: The port on the Pod to forward traffic to.
Spring Boot Deployment: Deploys a single instance of a Spring Boot application, exposing port 8080, and configured to communicate with MongoDB using environment variables.
Spring Boot Service: Exposes the Spring Boot application using a NodePort service, making it accessible outside the cluster.
MongoDB Deployment: Deploys a single instance of MongoDB, exposing port 27017, and configured with initial root credentials.
MongoDB Service: Exposes the MongoDB instance using a ClusterIP service, making it accessible within the cluster.
Step 4: Here is my pods for the Kubernetes for the spring application and mongo database. Refer the below image for your reference.
kubectl get pods

Step 5: Here is the services of the both deployments.
kubectl get svc

Step 6: Here are the deployments of the both applications that is spring app and mongo database.
kubectl get deployments

Step 7: Here is the all services after applying the manifest file in the kubernetes.
kubectl get all

Step 8: Access the spring boot application.

Step 9: Insert the data into data base using the spring boot application. Here we have inserted the sample data into the mogo db databse refre the below image for your reference.

Conclusion
Deploying a Spring Boot application on Kubernetes simplifies the process of managing and scaling microservices. By leveraging Kubernetes' robust infrastructure, we ensure that our application is resilient, scalable, and easy to manage. The integration with MongoDB demonstrates how Kubernetes can effectively handle data persistence alongside application deployment. This step-by-step guide showcases the essential steps and configurations required, providing a comprehensive foundation for deploying Java-based applications in a modern, cloud-native environment.
Similar Reads
DevOps Tutorial DevOps is a combination of two words: "Development" and "Operations." Itâs a modern approach where software developers and software operations teams work together throughout the entire software life cycle.The goals of DevOps are:Faster and continuous software releases.Reduces manual errors through a
7 min read
Introduction
What is DevOps ?DevOps is a modern way of working in software development in which the development team (who writes the code and builds the software) and the operations team (which sets up, runs, and manages the software) work together as a single team.Before DevOps, the development and operations teams worked sepa
10 min read
DevOps LifecycleThe DevOps lifecycle is a structured approach that integrates development (Dev) and operations (Ops) teams to streamline software delivery. It focuses on collaboration, automation, and continuous feedback across key phases planning, coding, building, testing, releasing, deploying, operating, and mon
10 min read
The Evolution of DevOps - 3 Major Trends for FutureDevOps is a software engineering culture and practice that aims to unify software development and operations. It is an approach to software development that emphasizes collaboration, communication, and integration between software developers and IT operations. DevOps has come a long way since its in
7 min read
Version Control
Continuous Integration (CI) & Continuous Deployment (CD)
Containerization
Orchestration
Infrastructure as Code (IaC)
Monitoring and Logging
Microsoft Teams vs Slack Both Microsoft Teams and Slack are the communication channels used by organizations to communicate with their employees. Microsoft Teams was developed in 2017 whereas Slack was created in 2013. Microsoft Teams is mainly used in large organizations and is integrated with Office 365 enhancing the feat
4 min read
Security in DevOps