Why a Keycloak cluster needs a load balancer configured for it
Putting a load balancer in front of a Keycloak cluster is what lets login traffic reach more than one node, and it has to be configured for Keycloak's behavior rather than left at defaults. A load balancer configured for Keycloak spreads authentication requests, token endpoint calls and admin traffic across the nodes, removes a failed node from rotation, and gives clients one stable hostname. Without it, a cluster of healthy nodes still behaves like a single server, because every client is pinned to whichever address it was first given and a node failure interrupts the sign-ins it was serving.
The load balancer is a required part of high availability, not an optional convenience. Keycloak's HA overview describes supported architectures in which a single cluster may be spread across availability zones, and both supported multi-cluster designs depend on a synchronously replicated database. Teams should confirm with the Keycloak high availability overview which architecture fits their topology before choosing a load balancer product, because the health checks, failover behavior and zone placement each depend on it. The database requirement matters here too: a load balancer can move traffic to a healthy node, but it cannot make a node's session and data state consistent if the database behind the cluster is not synchronously replicated.
Teams usually need this work when they move from one Keycloak node to several, when they spread nodes across availability zones, or when a regulator, customer contract or internal policy sets an uptime expectation that a single node cannot meet. Each of these cases raises the same questions the rest of this topic answers: how traffic is distributed, which endpoints are exposed, how the management port is probed, and how TLS and timeouts are handled. Settling the architecture first lets the load balancer design follow from it rather than being retrofitted after go-live.
Load balancer options and when each fits
This table compares cloud-managed load balancers, Kubernetes ingress with the Keycloak Operator, and software load balancers on virtual machines across TLS handling, health checks, path routing and operating responsibility. Read each row as a question to put to the vendor or platform team, because product behavior must be confirmed in your environment before you commit.
| Decision point | Cloud-managed load balancer | Kubernetes ingress or Operator-managed service | Software load balancer on virtual machines |
|---|---|---|---|
| TLS termination or re-encryption | Confirm whether the service can terminate TLS and re-encrypt to Keycloak nodes over HTTPS, and whether it can validate the node certificate | Confirm whether the ingress controller can pass TLS through or re-encrypt to the pod, and where the certificate for each hop is issued | Usually configurable for both termination and re-encryption, but certificate handling and renewal are your responsibility |
| Health check support | Confirm the service can probe the management port health endpoints and set the expected status codes and intervals | Confirm the ingress or service can reach the management port, since health endpoints are not always exposed on the public port | Available in most software balancers, so confirm the exact probe type and the path you configure |
| Path routing | Confirm rules can expose only the public paths and block admin console and Administration REST API paths on the public hostname | Confirm ingress rules can restrict paths by host and prefix, and whether the Operator manages the hostname split | Path rules are configured by hand, so review them against the production guide after every change |
| Timeouts and idle settings | Confirm idle and response timeouts can be raised for token and login flows without affecting other services | Confirm the controller exposes timeout and buffer annotations, and how they are set per Keycloak ingress | Full control of timeouts, but each change must be tested under load |
| Session affinity | Confirm the service can route without sticky sessions as your Keycloak version expects, and check any cookie settings you need | Confirm the ingress does not add cookie affinity that you did not intend | Confirm what the balancer does by default and disable affinity unless your version requires it |
| Who operates it | The cloud provider runs the balancer, but you own listeners, certificates, rules and the cost of changes | Your platform team operates the controller, and the Operator manages Keycloak resources, so ownership must be written down | Your team patches, monitors and scales the balancer pair, including failover between balancers |
| Best fit | Teams on one cloud account who want managed capacity and accept the provider's configuration limits | Teams already running Kubernetes who want routing and Keycloak resources in one declarative model | Teams in restricted or on-premises networks, or where the balancer must match existing standards |
How client requests reach Keycloak nodes
A request starts at the public hostname, passes the load balancer and the reverse proxy, and lands on a Keycloak node. The admin hostname and the management port sit on separate paths, and the health endpoint is reached only from inside the network. Every node writes to one synchronously replicated database. Check where TLS ends at each hop, which paths the proxy exposes, and that nothing public reaches the admin console or the management interface.
Request path from public clients through the edge to Keycloak nodes and the database.
Configuring the load balancer step by step
This sequence takes a Keycloak cluster from bare nodes to a load balancer that sends only login and protocol traffic to healthy nodes, keeps the admin surface private, and encrypts traffic end to end. Each step ends with a check you can run before moving on.
Enable the management interface and metrics
The platform team starts each Keycloak node with the management interface enabled and, where the monitoring stack needs it, metrics switched on with --metrics-enabled=true. The health endpoints and the /metrics path are served on the management port, so the load balancer probes a port that is separate from public traffic. Confirm the setup by requesting the health endpoint on the management port of each node directly, bypassing the load balancer, and checking that it returns a success response. Also confirm that /metrics answers only on the management port, not on the public hostname.
Configure health checks against the management port
Point the load balancer's health checks at the readiness and liveness endpoints on the management port, not at the public login page. Set the check to mark a node unhealthy after repeated failures so one slow response does not pull it out of rotation. Confirm the probe settings against your load balancer's documentation and the current Keycloak health check guidance. The step is done when the load balancer shows every node as healthy and the pool lists the nodes you expect.
Set up TLS re-encryption with team-controlled certificates
Terminate client TLS at the load balancer with a certificate your team issues and renews, then open a new TLS connection from the load balancer to each Keycloak node. Keycloak's production guide expects TLS on all communication, so plaintext hops between the balancer and the nodes are not acceptable. Store the node certificates and the trust chain the balancer uses under your key management process, and record their expiry dates. Verify by inspecting the certificate presented to a client and the one presented by a node, and confirm the balancer rejects a node whose certificate it does not trust.
Set connection and idle timeouts
Set the balancer's connect, idle and response timeouts so they are longer than the slowest normal login or token request your clients produce, and make sure they agree with the proxy settings on the Keycloak side. Mismatched timeouts show up as intermittent 502 or 504 responses that look like application bugs. Agree the values with your team and load test results rather than copying defaults from another product. The check is a controlled slow request, such as a long-running token exchange in a test realm, that completes without the balancer cutting the connection.
Expose only public login and protocol paths
Create balancer routing rules that forward only the paths clients need for sign-in and protocol flows, such as the realm endpoints for OpenID Connect and SAML and the resources the login pages load. Deny everything else at the edge, including unrelated management and metrics paths. Keycloak's production guide calls for a reverse proxy with path restrictions, so this rule set is part of the hardening work, not an optional extra. Verify by requesting each blocked path from the public hostname and confirming it returns a denial, while a test login through the allowed paths still completes.
Route the admin console and Administration REST API separately
Serve the admin console and the Administration REST API on a different hostname or context path from the public frontend URLs, and restrict that route to administrator networks or a VPN. Keep the admin route on a separate listener or rule set so a misconfigured public rule cannot expose it. Confirm the Keycloak hostname settings match the split so that redirects and issuer values point at the correct public URL. The check is an attempt to open the admin console from an untrusted network, which should fail, and a successful admin login from the approved network.
Test failover by removing a node from rotation
Stop the Keycloak service on one node, or block its health port, and watch the balancer mark it unhealthy and stop sending it traffic. Run a steady stream of test logins during the failure to confirm that users see no errors beyond any in-flight requests. Then restore the node and confirm it rejoins the pool after its checks pass. Record the observed detection and recovery behavior in your runbook, because that is the figure your operations team will rely on during a real incident.
Timeouts and paths to expose on the public hostname
The load balancer should publish only the paths that browsers, applications and token clients need, and keep everything operational on a different hostname or context path. Public paths are the OpenID Connect and OAuth 2.0 endpoints under the realm, the SAML endpoints for each realm that uses SAML, the login and registration pages, and the static resources those pages load. The private surface is the admin console, the Administration REST API and the management endpoints such as /metrics and the health checks. Keycloak's production guide expects the admin console and Administration REST API to sit on a separate hostname or context path from the public frontend URL, so the load balancer rules should reject those paths on the public listener rather than relying on applications to avoid them. Confirm the exact path list against the Keycloak production configuration guide for your version before writing the rules, because the set of paths and the way the frontend URL is configured change between releases.
Timeouts need to be set per route class, not once for the whole listener. Login and token flows are short request and response exchanges, so an idle timeout only has to cover the gap between the user's browser requests and the proxy's upstream keep-alive. Connect and read timeouts should be short enough that a failing node is removed from rotation quickly, but long enough that a slow database commit during a login does not produce a gateway error that the user sees as a failed sign-in. Test these values with a deliberate slow-database scenario in your staging cluster, and compare the load balancer's timeout with the Keycloak request and database timeouts so the proxy never gives up before the server does. Long-lived connections are a separate case: if you expose any streaming or long-poll behavior, give those routes their own timeout rather than raising the global value. Backchannel calls from your applications to the token and introspection endpoints run on the internal network in most designs, so decide whether they use the public hostname at all, and apply the same rules to them. Ask your load balancer vendor how each timeout is measured (per request, per idle connection or per upstream attempt) before you copy values from another deployment.
Security considerations at the load balancer
The load balancer is the public face of a Keycloak cluster and the place where most exposure decisions are made. The controls below decide what the internet can reach, how traffic is encrypted between hops, and which addresses Keycloak trusts when it reads client information. Each one should be checked in the proxy configuration and in the Keycloak settings that depend on it.
TLS on every hop
Terminate TLS at the load balancer with a certificate for the public hostname, then re-encrypt the connection to each Keycloak node rather than sending plain HTTP across the internal network. Keycloak's production guide calls for TLS on all communication, so confirm that the proxy validates the node certificate and does not skip verification. Check that no listener on port 80 forwards login traffic in clear text.
Keycloak production guideKeep metrics and health off the public network
The /metrics endpoint and the health endpoints run on the management interface, and they reveal cache, request and runtime detail that attackers can use for reconnaissance. Block these paths at the load balancer and allow them only from the monitoring network and the health checker. Confirm the management port is not published on a public address in the node's network policy or security group.
Separate admin hostnames and paths
Serve the admin console and the Administration REST API on a hostname or context path that is different from the public frontend URLs. Route only the paths your applications need to the public listener, and restrict the admin hostname by network range or VPN. Verify with a test request that an admin path returns an error on the public hostname.
Trust forwarded headers only from the proxy
Keycloak builds redirect URLs, issuer values and client IP records from forwarded headers when it sits behind a proxy. Accept these headers only from the load balancer's addresses, and make sure the proxy overwrites any client-supplied X-Forwarded-* values. Wrong trust settings can allow a client to spoof its address in login audit records or change the host used in generated links.
Certificate rotation ownership
Name one team that owns the public certificate, the internal re-encryption certificates and the trust store that the proxy uses to validate nodes. Record expiry dates in a shared calendar and test renewal before the old certificate expires. An expired certificate at the load balancer stops every login at once, so ask who is paged and how a rotation is rolled back.
Log access to admin paths
Send load balancer access logs for the admin hostname and the admin paths to your central log store, and keep them separate from routine traffic so they are easy to search. Record the source address, user agent and response code for each request. Confirm the retention period with your security team, since these logs are often needed during an incident review.
Questions teams ask before configuring a Keycloak load balancer
How much effort does configuring a Keycloak load balancer take, and what drives it?
The effort depends on how many nodes you run, how many public hostnames and paths you expose, and whether TLS terminates at the load balancer, re-encrypts to the nodes, or passes through. A single cluster behind one hostname is a small configuration task. Effort grows with separate hostnames for the admin console and public frontend, health check wiring, and the timeout and header settings your login and token flows need. Your team pays for the design, the configuration in your load balancer product, and testing login, token refresh and logout through it. Ask any provider for a quote built from a written list of hostnames, paths, nodes and TLS mode.
Can our team configure the load balancer without outside help?
Yes, if your team already runs the load balancer and can work through Keycloak's production guide and upgrade notes. The core configuration is ordinary reverse proxy work: a backend pool of Keycloak nodes, health checks, TLS, and path rules. Outside help is most useful where the design involves several linked decisions, such as splitting admin and public hostnames, routing identity provider callbacks to the cluster, or keeping the setup stable during a rolling upgrade. Test real login, token refresh and logout flows through the proxy before cutting over, beyond a health check returning success. DeployOpen plans, implements and tests these setups in infrastructure you control, under a fixed scope agreed in writing.
What does the work need from our network, certificates, DNS and database?
Expect to provide network paths from the load balancer to every Keycloak node and to the database, DNS records for each public and admin hostname, TLS certificates for those hostnames, and a decision on whether the proxy re-encrypts traffic to the nodes. You also need access to the load balancer configuration and to firewall rules for the management interface, which should stay off the public network. Database access matters mainly for checking connection behavior and any migration plan during upgrades. Confirm with your security team who issues and renews certificates, which certificate authority you use, and whether your policy requires encryption on internal traffic. Gather these before the design session so the work is not blocked midway.
How long does a Keycloak load balancer setup take in our environment?
No fixed duration applies, because the timeline depends on your environment: the number of hostnames and paths you expose, whether a cluster already exists, how many load balancer products or environments need changes, and how long your change approval and test windows take. A new single cluster with one hostname is a much smaller job than replacing a shared proxy that serves many applications. Ask for a timeline in the written scope, and make sure it includes a test phase with real identity flows, a staging run and a documented rollback path. The scope conversation is the right place to agree a timeline for your specific setup.
Do we still need sticky sessions on recent Keycloak releases?
Recent Keycloak releases distribute requests evenly across nodes, so sticky sessions are no longer required for normal operation from release 26.6 onward. Check the release notes for your exact version before you remove stickiness. Older releases relied on sticky sessions to keep a user's requests on the node holding their session state. Test any flow that might depend on a single node, including admin sessions and any custom providers you run. Keeping stickiness during a transition can serve as a safeguard until testing shows that even distribution works for your clients and workflows.
What changes in the load balancer when we upgrade Keycloak?
The load balancer configuration changes less than the Keycloak nodes do, but an upgrade affects how traffic reaches the cluster. The Keycloak 26.8 upgrade notes include enforced SMTP StartTLS, mandatory signature validation for backchannel logout tokens from external providers, login failures persisted to the database by default, and a recommendation to move from the deprecated multi-site feature to the stateless feature. Some of these affect email, logout and cluster design, which can change what the proxy must route. Plan rolling node updates so healthy nodes stay in the pool, check health endpoints at each step, and decide in advance whether schema migration runs at startup or manually. The upgrading guide covers these steps, and the Keycloak upgrades topic goes further.
Which Keycloak paths should the load balancer expose publicly?
Expose only the paths that public users and applications need, such as the login and token endpoints, the discovery document, the signing keys endpoint, and the account pages you actually serve, along with the resources those pages load. Keep the admin console and the Administration REST API on a different hostname or context path from public frontend URLs, and block them at the proxy for public networks. Keycloak's production guide calls for a reverse proxy with path restrictions and TLS on all communication. Test each path you open and each path you block, including unusual casing and encoded characters. Document the list, because every added path is new public surface that your security review will question.
Should health checks use the management port or the public HTTP port?
Use the management interface for health checks and metrics when your Keycloak version exposes them there. Keycloak's configuration documentation describes the management interface as separate from public endpoints, which keeps probe traffic and operational endpoints away from users. Use the readiness endpoint to decide whether a node receives traffic, and the liveness endpoint to decide whether a node should be restarted. Keep both off the public internet. Metrics at /metrics require --metrics-enabled=true and the same network restriction. Confirm the exact endpoint paths and management address in the documentation for your version before you write probe rules.
How DeployOpen scopes and delivers Keycloak load balancer work
DeployOpen starts every Keycloak load balancer engagement with a written scope agreed before any configuration begins. That scope names the nodes behind the balancer, the public and admin hostnames, the TLS termination model, the health check and metrics ports, and the paths that will be exposed. It also states what is excluded, such as the database tier, DNS changes outside the balancer, or the multi-site design. Because most engagements are fixed-scope, the deliverables and the acceptance checks are written down with the scope so both sides know when the work is done.
Before any change, DeployOpen reviews the target architecture and network with your platform and security teams. The review covers which balancer you run (a cloud load balancer, a hardware appliance, or an ingress controller), whether traffic is re-encrypted to the nodes, which address the proxy headers come from, and whether the admin console and Administration REST API sit on a separate hostname or context path from public frontend URLs. Configuration then runs inside your own cloud accounts, data centers or restricted networks, under your change process. Confirm early which team owns the certificates, the balancer's idle timeout, and the firewall rules between the balancer and the Keycloak nodes, because these decide much of the configuration.
Failover and health check testing is the part that proves the design. DeployOpen tests node removal and restart during simulated logins and token refreshes, checks that the balancer stops routing to a node that fails its health check, and confirms that admin and metrics endpoints cannot be reached from public addresses. The work ends with documentation and handover: the final configuration, the test results, and a runbook for adding or draining a node. Ongoing upgrades and continuous testing are available as optional retainers, which you can agree separately from the initial scope.

