Cloud Native 9 min read

Step‑by‑Step Guide to Deploy a SpringBoot App on Kubernetes

This tutorial walks you through creating a simple SpringBoot web application, containerizing it with Docker, and deploying it to a Kubernetes cluster using Pods, Deployments, Services, and Ingress, while highlighting common pitfalls and comparing Java's resource usage to Go.

Su San Talks Tech
Su San Talks Tech
Su San Talks Tech
Step‑by‑Step Guide to Deploy a SpringBoot App on Kubernetes

SpringBoot Application Running on K8s

This article explains how to deploy a SpringBoot web application to a Kubernetes cluster, outlining six essential steps: writing the application code, building a container image, creating Pods, scheduling with a Deployment, exposing via a Service, and routing through an Ingress.

Write the Application Code

We start with a minimal HelloWorld‑level SpringBoot project managed by Maven. The pom.xml includes the spring-boot-starter-parent and the Spring MVC starter.

The source code is straightforward, demonstrating that SpringBoot handles much of the boilerplate for us.

Package the Application as a Container Image

Create a Dockerfile in the project root:

FROM openjdk:8-jre
ADD target/*.jar /application.jar
ENTRYPOINT ["java", "-jar", "/application.jar"]

Build and push the image to a remote registry:

docker build -t registry.cn-hangzhou.aliyuncs.com/docker-study-lab/simple-app-java:v0.1
docker push registry.cn-hangzhou.aliyuncs.com/docker-study-lab/simple-app-java:v0.1

Create the Deployment

Deployment is a composite controller that wraps a ReplicaSet, which manages pod replicas. Deployment adds rolling updates, health checks, and rollback capabilities.

Use the following YAML (image omitted for brevity) to define the Deployment. Initially copying a Go example caused OOM errors because the Java container needed more memory; increasing the limit to 500 MiB resolved the issue.

Expose the Service

After creating the Deployment, expose the application internally with a ClusterIP Service. The Service definition (image omitted) prepares for external exposure via Ingress.

Proxy the Service with Ingress

Install an Ingress controller (e.g., ingress‑nginx) and apply the Ingress YAML (image omitted) to route external traffic to the Service. After applying, access the app via java-app.example.com after adding the host entry to /etc/hosts.

Common kubectl Commands

kubectl apply -f xxx.yaml – create or update resources

kubectl get pod|deploy|svc|ingress – view resource status

kubectl describe pod|deploy|svc|ingress {$objectName} – detailed info

kubectl delete pod|deploy|svc|ingress {$objectName} – delete resources

Conclusion

This guide completes a basic end‑to‑end deployment of a SpringBoot app on Kubernetes, covering essential concepts and commands for beginners.

Compared to Go, Java applications typically consume more memory and result in larger container images (around 280 MiB versus a few megabytes for Go), highlighting trade‑offs in cloud‑native environments.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Cloud NativeDockerDeploymentKubernetesSpringBootIngress
Su San Talks Tech
Written by

Su San Talks Tech

Su San, former staff at several leading tech companies, is a top creator on Juejin and a premium creator on CSDN, and runs the free coding practice site www.susan.net.cn.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.