BlogKeycloak

Keycloak on Kubernetes: Operator Production Setup Guide

Scott Sternloff

By Scott Sternloff, Senior Enterprise Architect

LinkedIn · Updated · 5 min read

Keycloak on Kubernetes: Operator Production Setup Guide
On this page

Short answer

The supported way to run Keycloak on Kubernetes is the Keycloak Operator: install it, give it an external PostgreSQL (or other supported) database, then declare one Keycloak resource with a real hostname, TLS and at least two instances.

The supported way to run Keycloak on Kubernetes is the Keycloak Operator: install it, give it an external PostgreSQL (or other supported) database, then declare one Keycloak resource with a real hostname, TLS and at least two instances. The Operator does not run your database, and that is where most production work sits.

This guide follows the current upstream docs (Keycloak 26.8.2, read 4 December 2026) and the order of work we use in our Keycloak support work. Command lines are quoted from the official pages.

What do you need before you install the Keycloak Operator?

You need a database, a public hostname with a TLS certificate, and a decision on who terminates TLS. The Operator manages Keycloak pods, not the database, so the database must exist, be backed up and be sized before the first pod starts.

  • Database: the database guide lists PostgreSQL 14 to 18, MySQL 8.0 and 8.4, MariaDB, SQL Server and Oracle as supported, and says versions outside its table are not supported.
  • Hostname: the hostname guide says production needs either hostname set or hostname-strict explicitly false, and that strict mode should stay on unless your proxy overwrites the Host header.
  • Ingress: the Operator creates an Ingress by default; if you use your own, you point it at the <cr-name>-service Service.

How do you install the Keycloak Operator on Kubernetes?

Create a namespace and apply the Operator manifests with kustomize at the version tag you chose. The installation page does this in two commands and notes the Operator watches only the namespace it is installed in, unless you use the cluster-wide variant.

  1. Create the namespace: kubectl create namespace keycloak
  2. Apply the manifests, pinning the tag: kubectl apply -k 'github.com/keycloak/keycloak-k8s-resources/kubernetes?ref=26.8.2'
  3. Confirm the CRDs exist (keycloaks.k8s.keycloak.org and keycloakrealmimports.k8s.keycloak.org) and the Operator pod is running.

The guide warns that kubectl delete -k on the same kustomization also deletes the CRDs, and with them your Keycloak resources. Keep the Operator version in step with the server version you run, and read the official installation page for the cluster-wide option.

How do you deploy a production Keycloak with the Operator?

Create a database credentials Secret, a TLS Secret, then a Keycloak custom resource that references both. The basic deployment guide gives a working example; treat it as a starting point, not the finished production file.

  1. Create the database Secret: kubectl create secret generic keycloak-db-secret --from-literal=username=... --from-literal=password=...
  2. Create the TLS Secret from your CA-issued certificate: kubectl create secret tls example-tls-secret --cert certificate.pem --key key.pem
  3. Write the Keycloak resource (apiVersion k8s.keycloak.org/v2beta1) with the fields in the table below, then kubectl apply -f it.
  4. Read the status conditions with the go-template command from the guide until ready.
  5. Fetch the generated <cr-name>-initial-admin Secret, sign in, change the credentials and enable MFA, as the guide advises.
FieldWhat it setsProduction note from the docs
spec.instancesReplica countRolling updates avoid downtime only with at least two replicas
spec.dbVendor, host, credential SecretsThe Operator does not manage the database
spec.http.tlsSecretCertificate and keyUse httpEnabled: true only for edge or re-encrypt TLS
spec.hostname.hostnamePublic hostnameMust match what clients and issuers see
spec.proxy.headersforwarded or xforwardedOmit it and a legacy default logs deprecation warnings
spec.networkPolicyAccess to the ingress controllerLimits header spoofing

How many instances and what update strategy should you use?

Run at least two instances and choose the update strategy on purpose. The production guide says two or more instances let logins survive a node failure, and the rolling-updates page says rolling updates avoid downtime only when at least two replicas are running.

The spec.update.strategy field takes three values, per the rolling updates page:

StrategyBehavior
RecreateOnImageChange (default)Scales the StatefulSet down before applying a new image, so there is downtime
AutoRuns a check Job and rolls only when the change is the same version or a patch within the same major.minor stream
ExplicitRolls when spec.update.revision is unchanged; you take responsibility for compatibility

The same page lists two prerequisites: nodes must stop gracefully on TERM, and the load balancer must honor the readiness probe. Production guidance also says to route traffic using /health/ready. For placement, spec.scheduling accepts affinity, tolerations and topology spread constraints, and the Operator spreads pods across zones and nodes by default.

What should you verify before going live?

Verify that you can lose a pod, restore the database and upgrade the server without surprises. A green status condition proves the pods started; it does not prove any of these three.

  1. Delete one pod under load and confirm sign-ins continue.
  2. Restore a database backup into a scratch environment and start Keycloak against it. The database guide gives no backup procedure, so this is yours to define.
  3. Check the hostname: open the OpenID configuration endpoint and confirm every URL uses the public hostname.
  4. Confirm only the paths you intend to expose reach the internet; the production guide says to block REST API paths at the proxy if they should not be public.
  5. Set resource requests and limits in spec.resources; the Operator defaults are 1700MiB requested and 2GiB limit when unset.
  6. Rehearse a patch upgrade and read the RecreateUpdateUsed condition to see which path was taken.

When should you ask for help?

Ask when the first upgrade, a database restore or a multi-node session problem is closer than your team's experience. AceMQ's senior engineers support Keycloak on the Operator or on other installs, community or Red Hat build; see Keycloak consulting for design reviews and Keycloak support for 24/7 operations.

We sell no Red Hat subscription and give no Red Hat licensing advice. Defects in Red Hat's own build go to Red Hat. For what comes next, see our notes on upgrade and rollback failure modes.

Sources

Frequently Asked Questions

Should I use the Keycloak Operator or a Helm chart?

The Operator is the Keycloak project's own Kubernetes install route and is the one documented on keycloak.org. Third-party Helm charts are maintained elsewhere. Pick whichever your team can upgrade and debug, and keep the Keycloak version and your database versions inside the supported lists.

Does the Keycloak Operator manage the database?

No. The basic deployment guide states the Operator does not manage the database. You supply a supported database, the host and credentials through Secrets, and you own its backups, sizing and upgrades.

How many Keycloak instances do I need in production?

At least two. Keycloak's production guide says two or more instances let logins survive a node failure, and the Operator's rolling-update page says rolling updates avoid downtime only with at least two replicas running.

Scott Sternloff

Author

Scott SternloffSenior Enterprise Architect

Senior Enterprise Architect at AceMQ. Writes the technical coverage here: RabbitMQ, Kafka and Redis architecture, clustering and migrations.

Talk to an engineer

Need a hand with Keycloak?

Senior engineers who run it in production. Get a quote or a free consultation, no sales pitch.

Free Consultation

Get Expert Eyes on Your Keycloak Environment

Whether you're troubleshooting a production incident, planning a migration, or want a second opinion on your architecture — our team is ready. No pitch, just answers.

Email Us