Repository navigation
Replies: 2 comments 21 replies
|
Thank you for starting this discussion. My 2 cents on this:
About checking if the database is readonly or not: I think I remember that you mentioned PostgreSQL as the database. This supports the I'm not sure what the instance should do when the database is no longer reachable, and how long it should take to kill/exit the Pod. Usually an overloaded database or a temporary network glitch are no good reasons to restart Pod, as it would lead to cascading failures. Let's defer that part. cc: @pruivo - what are your thoughts on this? |
|
We're currently exploring a active-hot-standby where the Keycloak instance in the other datacenter is actually running, see #49469 With that, the standby would connect in primary database and use it to receive for example invalidations. This would be sufficient for synchronous database failovers. For asynchronous database failovers, some data might be lost. For that, one would want to clear caches. For that, #46814 would need to be implemented. With one of those, or both, implemented, I don't think there is any additional need for additional functionality as long as the instances in the secondary DC can connect to the DB in the primary DC. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Problem
Keycloak currently expects the configured database to be writable during startup.
That becomes a problem in failover setups where Keycloak is already running in a standby region, but the local database is still a read-only replica. In that case Keycloak cannot finish startup, because startup still includes steps that need write access, for example schema migration and JDBC-Ping.
Also the database might become read-only again after Keycloak has already started.
Use case
The setup I have in mind is a warm standby across regions:
The main goal here is to keep failover time low once the database is writable.
What seems to be missing
What seems to be missing is a supported way to keep Keycloak blocked until the configured database is actually writable.
A command like
kc.sh wait-for-writable-dbwould already help. It could wait until the configured database accepts writes and then exit successfully.My first thought was to use that in a Kubernetes init container, but that does not really solve the whole problem, because init containers are not run again when the pod restarts.
So at the moment I see two viable options:
A) Wait in the container entrypoint
Run
kc.sh wait-for-writable-dbbeforekc.sh start.That would be simple and would not require changing Keycloak's startup model much. The downside is that while the container is waiting, Keycloak itself is not up yet, so its normal health endpoints are not available. Kubernetes would eventually kill the pod. To deal with that, we would need some lightweight health endpoint during the waiting phase.
B) Start partially, then finish initialization later
Start the server and expose health endpoints first, keep readiness DOWN, and wait in the background until the database becomes writable. After that, continue the remaining initialization and only then become ready.
Operationally this feels cleaner, but it is also a much bigger change because it would split initialization into an earlier and a later phase.
Runtime behavior
There is also the runtime side of this.
If the database turns read-only again later, I do not think readiness alone is enough. Keycloak cannot really keep operating in that state. It would probably need to leave the cluster and restart into the same waiting mode until the database is writable again.
Questions
All reactions