Keycloak + Postgres on Kubernetes is always restarting and loosing data

Hi,

I am struggling with something I can’t seem to knock down or even isolate. I have a kubernetes deployment for my keycloak server. Nothing special, typically the same as what we could find on the official keycloak documentation. My problem is, keycloak is very often, rebooting, like restarting itself and then the data is lost.
What happens
Sometimes, i go back to the admin console, then i can see it can’T load, Then i go check my postgresql instance then I see a lot of SQL errors. Then I can see that keycloak can’t seem to find the data it tries to look for. Then i check keycloak pod and I can see some JBoss Server stop executiong error. From my assumption, it looks like keycloak is just stopping or breaking for any reasons then It reload everythings from scratch.

What i tested
1. Testing reboot myself
Saving data.
Rebooting myself keycloak pod
I can see the data I saved previously.

*2. Upgrading version

  1. Testing with upgrading Keycloak from 15 to 16, or going down til version 11

*3. Updating Postgresql version

  1. Tested with Postgres 13 and 10

I can’t find whats going on. This never happened to me on docker-compose for example. It looks like keycloak is loosing DB connection or it fails then keycloak reacts into restarting from scratch and overwriting everything. But i can’T seem to understand whats failing first, the DB, or keycloak.

Does this ring any bells to anyone ?

Thanks