Member-only story
DevOps, Cloud Computing
Kubernetes Persistent Volume Case Study: Deploy a Spring Boot App with a Postgres DB
This article is an excerpt from my video course Modern Software Engineering: Architecture, Cloud & Security available with a limited time discount.
Want to try something real with Kubernetes?
Let’s deploy a Spring Boot Application with a PostgreSQL database that needs persistent storage. This way, you’ll get hands-on experience managing stateful and stateless applications on Kubernetes.
Here are the steps to achieve this using Kubernetes:
- Create a Persistent Volume and Persistent Volume Claim for the PostgreSQL database.
- Set up a Deployment to manage the PostgreSQL database and ensure persistence.
- Deploy the Spring Boot App using a Deployment, which is a stateless application.
- Expose both PostgreSQL and the Spring Boot App using Services.
- Access the PostgreSQL database and make sure everything is running smoothly.
Note: Part 1 of my Kubernetes hands-on tutorial is available here, and part 2 is available here.
Step 1: Prerequisites
Before you begin, ensure you have the following set up:
- A running Kubernetes cluster: you can use Minikube, Kind, or any managed Kubernetes service like GKE, EKS, etc. In my case, I’m using Minikube and Docker Desktop for a local Kubernetes deployment on my local machine. So after starting Docker Desktop to make the Docker Daemon available, I need to start Minikube by running the command
minikube start
. - kubectl CLI installed and configured to communicate with your cluster.
- Helm (optional but recommended for easier management).
Step 2: Create a Persistent Volume (PV) and Persistent Volume Claim (PVC) for PosgreSQL
PostgreSQL needs a persistent disk to store data. We’ll define a PersistentVolume and a PersistentVolumeClaim (PVC) that our database will…