Chapter 10. Deploying Red Hat build of Keycloak for HA with the Operator
Deploy Red Hat build of Keycloak for high availability with the Red Hat build of Keycloak Operator as a building block.
This guide describes advanced Red Hat build of Keycloak configurations for Kubernetes which are load tested and will recover from single Pod failures.
These instructions are intended for use with the setup described in the Concepts for multi-site deployments chapter. Use it together with the other building blocks outlined in the Building blocks multi-site deployments chapter.
10.1. Prerequisites Copy linkLink copied to clipboard!
- OpenShift or Kubernetes cluster running.
- Understanding of a Basic Red Hat build of Keycloak deployment of Red Hat build of Keycloak with the Red Hat build of Keycloak Operator.
- Aurora AWS database deployed using the Deploying AWS Aurora in multiple availability zones chapter.
- Data Grid server deployed using the Deploying Data Grid for HA with the Data Grid Operator chapter.
- Running Red Hat build of Keycloak with OpenJDK 21, which is the default for the containers distributed for Red Hat build of Keycloak, as this enabled virtual threads for the JGroups communication.
10.2. Procedure Copy linkLink copied to clipboard!
- Determine the sizing of the deployment using the Concepts for sizing CPU and memory resources chapter.
- Install the Red Hat build of Keycloak Operator as described in the Red Hat build of Keycloak Operator installation chapter.
- Notice the configuration file below contains options relevant for connecting to the Aurora database from Deploying AWS Aurora in multiple availability zones
- Notice the configuration file below options relevant for connecting to the Data Grid server from Deploying Data Grid for HA with the Data Grid Operator
- Build a custom Red Hat build of Keycloak image which is prepared for usage with the Amazon Aurora PostgreSQL database.
Deploy the Red Hat build of Keycloak CR with the following values with the resource requests and limits calculated in the first step:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- The database connection pool initial, max and min size should be identical to allow statement caching for the database. Adjust this number to meet the needs of your system. As most requests will not touch the database due to the Red Hat build of Keycloak embedded cache, this change can server several hundreds of requests per second. See the Concepts for database connection pools chapter for details.
- 2 3
- Specify the URL to your custom Red Hat build of Keycloak image. If your image is optimized, set the
startOptimized
flag totrue
. - 4
- Enable additional features for multi-site support like the loadbalancer probe
/lb-check
. - 5
- To be able to analyze the system under load, enable the metrics endpoint.
10.3. Verifying the deployment Copy linkLink copied to clipboard!
Confirm that the Red Hat build of Keycloak deployment is ready.
oc wait --for=condition=Ready keycloaks.k8s.keycloak.org/keycloak oc wait --for=condition=RollingUpdate=False keycloaks.k8s.keycloak.org/keycloak
oc wait --for=condition=Ready keycloaks.k8s.keycloak.org/keycloak
oc wait --for=condition=RollingUpdate=False keycloaks.k8s.keycloak.org/keycloak
10.4. Optional: Load shedding Copy linkLink copied to clipboard!
To enable load shedding, limit the number of queued requests.
Load shedding with max queued http requests
spec: additionalOptions: - name: http-max-queued-requests value: "1000"
spec:
additionalOptions:
- name: http-max-queued-requests
value: "1000"
All exceeding requests are served with an HTTP 503.
You might consider limiting the value for http-pool-max-threads
further because multiple concurrent threads will lead to throttling by Kubernetes once the requested CPU limit is reached.
See the Concepts for configuring thread pools chapter about load shedding for details.
10.5. Optional: Disable sticky sessions Copy linkLink copied to clipboard!
When running on OpenShift and the default passthrough Ingress setup as provided by the Red Hat build of Keycloak Operator, the load balancing done by HAProxy is done by using sticky sessions based on the IP address of the source. When running load tests, or when having a reverse proxy in front of HAProxy, you might want to disable this setup to avoid receiving all requests on a single Red Hat build of Keycloak Pod.
Add the following supplementary configuration under the spec
in the Red Hat build of Keycloak Custom Resource to disable sticky sessions.