KubeKanvas Logo
  • Features
  • Pricing
  • Templates
    • How KubeKanvas works
    • Docs
    • Downloads
    • Blog
    • E-Book
    • Tutorials
  • FAQs
  • Contact
  • Features
  • Pricing
  • Templates
    • How KubeKanvas works
    • Docs
    • Downloads
    • Blog
    • E-Book
    • Tutorials
  • FAQs
  • Contact
Back to Templates

Deploy a Spring Boot Application on Kubernetes with PostgreSQL

Tags:
springbootingresspostgreskubekanvaskubernetes
Created by:
Mahmood
Deploy a Spring Boot Application on Kubernetes with PostgreSQL template preview
4 uses
KubeKanvas Logo
Visual Kubernetes cluster design tool that helps you create, manage, and deploy your applications with ease.
Product
  • Features
  • Pricing
  • Templates
Resources
  • Blog
  • Tutorials
Company
  • About Us
  • Contact
  • Terms of Service
  • Privacy Policy
  • Impressum
XGitHubLinkedIn
© 2026 KubeKanvas. All rights reserved.

Connecting a Spring Boot application to a PostgreSQL database on Kubernetes requires more than running two pods side by side. The database needs a stable hostname your application can rely on across pod restarts, credentials need to stay out of your container image, and external traffic needs a consistent entry point. This template wires all of that together using a StatefulSet-backed PostgreSQL database, headless DNS for stable database addressing, Kubernetes Secrets for credential injection, and NGINX Ingress for external routing.

What's Included

ComponentTypePortRole
Spring Boot AppDeployment + ClusterIP Service8080Stateless application tier connecting to PostgreSQL via headless DNS
PostgreSQLStatefulSet5432Database backend deployed as a StatefulSet for stable pod identity (postgres-0) and guaranteed PVC reattachment
Headless ServiceService-Gives PostgreSQL a predictable DNS address (postgres-0.postgres-service) that does not change when the pod restarts
SecretSecret-Database credentials stored outside the image and injected as environment variables at pod startup
NGINX IngressIngress80Routes external requests to the Spring Boot service at /frontend-service

Architecture Overview

The Spring Boot Deployment resolves the database host using the stable DNS name postgres-0.postgres-service, provided by the headless Service pointing directly at the StatefulSet pod. Unlike a standard ClusterIP Service that load-balances across multiple endpoints, the headless Service maps to the specific pod, giving the application a reliable connection target that survives pod restarts. Database credentials are injected from a Kubernetes Secret as environment variables at startup. NGINX Ingress routes external HTTP traffic to the Spring Boot ClusterIP Service at /frontend-service.

Prerequisites

  • A running Kubernetes cluster (Docker Desktop or Minikube)
  • NGINX Ingress Controller installed and enabled
  • Storage class configured for dynamic PVC provisioning
  • KubeKanvas CLI installed and running on your computer (Optional, if you want to use one-click deployment)

How to Deploy

  1. Click Use Template to load the manifest into the editor.
  2. Update the Secret with your PostgreSQL username and password.
  3. Confirm the Ingress host and path match your intended endpoint configuration.
  4. Deploy the template to your cluster via the Play button in the top right bar. If you prefer to deploy manually, download the YAML and apply it with kubectl.
  5. Wait for all pods to reach Running status. You can monitor progress in the Release Monitor screen.

How to Test

  1. Confirm both the Spring Boot and PostgreSQL pods are running: kubectl get pods -n <namespace>.
  2. Send a request to the application endpoint: curl http://<ingress-ip>/frontend-service and confirm a response is returned.
  3. Check the Spring Boot pod logs to confirm successful database connection: kubectl logs <springboot-pod> -n <namespace>.
  4. Verify the Ingress routing is active: kubectl describe ingress -n <namespace>.

Use Cases

  • Spring Boot and PostgreSQL on Kubernetes: Running a standard Spring Boot and PostgreSQL stack on Kubernetes with database connectivity handled through stable headless DNS instead of hardcoded IP addresses.
  • Stateless app with stateful database: Separating the application tier as a Deployment from the database tier as a StatefulSet to allow each to scale and restart independently.
  • Credential-isolated Spring Boot deployments: Injecting database credentials via Kubernetes Secrets rather than baking them into application properties or Docker images.
  • Ingress-routed Java applications: Using NGINX Ingress as a reverse proxy in front of a Spring Boot service for path-based external access.

Summary

This template configures a Spring Boot Deployment on Kubernetes connected to a PostgreSQL StatefulSet via headless DNS, with externalized credentials and NGINX Ingress routing for external access. The source code for the Spring Boot starter application is available at github.com/kubekanvas/deploy-springboot-kubernetes.