Optimizing User Sessions in Keycloak: Memory Management, Persistence, and Best Practices in Kubernetes

We are using Keycloak 20.0.5 in Kubernetes. We employ OpenID Connect to obtain JWT tokens, leading to the creation of a session for each request to acquire an access token using the username and password as part of the login flow. Users can also obtain a new access token using a refresh token.

We have allocated 700MB of memory for each pod and have observed that memory usage increases over time, eventually leading to pod restarts due to memory outage, resulting in the loss of sessions.

  1. What is the best practice for persisting user sessions to ensure users remain logged in after a restart?
  2. Can we utilize a centralized session storage solution, such as Redis, to retain user sessions?
  3. Are there any recommended methods to optimize memory usage?