Kubernetes Deployment for Spring Boot Applications

Deploying microservices on Kubernetes has become the de facto standard for cloud-native applications. In this post, you’ll learn Kubernetes deployment on Spring Boot using manifests for Deployment, Service, and health probes.

This guide walks through containerizing your app, writing YAML files, and running it locally with Minikube or any K8s cluster.

🧰 Prerequisites

To follow along, make sure you have:

  • Docker installed
  • Kubernetes cluster (Minikube or cloud provider)
  • kubectl CLI
  • springboot-docker-app image (from earlier post)
Kubernetes Deployment for Spring Boot Applications

πŸ“¦ Sample Spring Boot Application

Let’s use the same sample app in package:
com.kscodes.springboot.containers

Build your Docker image:

Push to Docker Hub (or private registry):

πŸ”§ Step 1: Kubernetes Deployment on Spring Boot – YAML

Create a file named deployment.yaml:

🌐 Step 2: Service YAML

Expose the app internally or externally. Create a file named service.yaml:

If you’re using Minikube, it will expose via NodePort or tunnel:

πŸ“¦ Step 3: Apply the YAMLs

Check the pods and service:

πŸ“‘ Accessing the App

If you’re on Minikube:

If you’re using a cloud cluster (GKE, EKS, AKS), it will create an external IP in the load balancer section.

πŸ”„ Rolling Update Example

Want to roll out a new version?

To undo:

πŸ”₯ Probes Explained

  • Liveness Probe: Kills the pod if it’s unhealthy
  • Readiness Probe: Routes traffic only when app is ready

These make Spring Boot services more resilient and reliable on Kubernetes.

πŸ“ Full File Structure

πŸ›‘οΈ Best Practices for K8s + Spring Boot

TipWhy It Helps
Use health probesImproves uptime and traffic control
Externalize configs with ConfigMapKeeps images clean
Use imagePullPolicy: IfNotPresentFaster redeploys in dev environments
Tag Docker images semanticallyAvoid β€œlatest” in prod

πŸ“˜ Summary

In this post, you deployed a Spring Boot app on Kubernetes using Docker and YAML manifests. You learned how to define a Deployment, expose it with a Service, and secure your app using liveness/readiness probes. This is the foundation for moving into advanced topics like ConfigMaps, Secrets, and Helm charts.