Connecting spring boot to postgres statefulset in Kubernetes

10/25/2021

I'm new to Kubernetes and I'm learning about statefulsets. For stateful applications, where the identity of pods matter, we use statefulsets instead of simple deployments so each pod can have its own persistent volume. The writes need to be pointed to the master pod, while the reading operations can be pointed to the slaves. So pointing to the ClusterIP service attached to the statefulset won't guarantee the replication, instead we need to use a headless service that will be pointing to the master. My questions are the following :

  • How to edit the application.properties in spring boot project to use the slaves for reading operations ( normal ClusterIP service ) and the master for writing/reading operations ( Headless service )?
  • In case that is unnecessary and the headless service does this work for us, how does it work exactly since it's pointing to the master ?
-- joe1531
kubernetes
kubernetes-statefulset
spring
spring-boot

0 Answers