Deploying a SpringBoot Application in Kubernetes with Postgresql and Ingress
In this template, well walk through the deployment of a Spring Boot application with a persistent PostgreSQL database.The deployment was managed via kubekanvas (a visual kubernetes IDE) . Here are the "pillars" of our K8s setup:
1. The Spring Boot Deployment
The application is "stateless" meaning if a pod dies, Kubernetes can simply spin up a new one without worrying about local data loss.The pod connects to PostgreSQL using a headless service DNS.
The kubekanvas/springbootstarter:latest image is pulled from Docker Hub by default, where the Kubernetes container runtime automatically expands it to https://hub.docker.com/r/kubekanvas/springbootstarter.
2. The StatefulSet
For databases, standard "Deployments" are risky because pod names and storage can change. By using a StatefulSet, we gave our Postgres pod a stable identity (postgres-0) and a Persistent Volume Claim (PVC). Even if the pod crashes, the data stays.
3. The Headless Service
We used a Headless Service (clusterIP: None) for our database. This gives our Spring Boot app a predictable internal DNS address: postgres-0.postgres-service.
4. The Secret
No passwords in plain text! We used a Kubernetes Secret to store our database credentials, injecting them into the Spring Boot container at runtime via environment variables.
5. Ingress
Router and reverse proxy that automatically discovers and configures routing for our services by connecting directly to Kubernetes.
Deployment & Access
The stack is accessible via NGINX Ingress. The Ingress routes requests with the /frontend-service path to the internal frontend-service (ClusterIP) on port 80.
http://<ingress-controller-address>/frontend-service
GITHUB Repository & deployment files: kubekanvas/deploy-springboot-kubernetes
