Sponsored by Hostzero
A Kubernetes operator for managing Keycloak resources declaratively. It uses the keycloak.hostzero.com/v1beta1 API group.
- Declarative management of Keycloak resources via Kubernetes CRDs
- Full Keycloak API support via
definitionfields - Automatic client secret synchronization to Kubernetes Secrets
- Hierarchical resource management (Instance β Realm β Clients/Users)
- GitOps-friendly: optionally keep Keycloak objects when CRs are deleted β see Preserving resources on deletion
- Helm chart for easy deployment
- High availability with leader election
- OpenTelemetry: optional OTLP traces and logs (Prometheus metrics included)
| Keycloak Version | Status |
|---|---|
| 20.x - 26.x | β Supported |
| 19.x and older | β Not supported |
Minimum supported version: 20.0.0
The operator validates the Keycloak version on connection and will fail to become ready if an unsupported version is detected. This ensures compatibility with modern Keycloak APIs and security features.
Note: From Keycloak 26.8.2 on, a client used with
auth.clientCredentialsneeds thekc-admin-apiclient scope. See KeycloakInstance.
Note: Red Hat Build of Keycloak (RHBK) versions are also supported as they map to upstream Keycloak versions (e.g., RHBK 24.x corresponds to Keycloak 24.x).
π Read the full documentation
This operator manages Keycloak instances and their resources (realms, clients, users, etc.) as Kubernetes Custom Resources. It provides:
- KeycloakInstance / ClusterKeycloakInstance: Connection to a Keycloak server
- KeycloakRealm / ClusterKeycloakRealm: Realm configuration
- KeycloakClient: OIDC or SAML client configuration
- KeycloakClientScope: Client scope configuration
- KeycloakProtocolMapper: Token claim mappers
- KeycloakUser: User management
- KeycloakUserCredential: User password management
- KeycloakGroup: Group management
- KeycloakRole: Realm and client roles
- KeycloakRoleMapping: Role-to-user/group assignments
- KeycloakIdentityProvider: External identity providers
- KeycloakComponent: LDAP federation, key providers
- KeycloakOrganization: Organization management (Keycloak 26+)
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Kubernetes Cluster β
β βββββββββββββββββββ βββββββββββββββββββββββββββββββββββββ
β β Keycloak β β Keycloak Operator ββ
β β Operator CRDs βββββΆβ ββββββββββββββββββββββββββββββ ββ
β β β β β Instance Controller β ββ
β β - Instance β β ββββββββββββββββββββββββββββββ€ ββ
β β - Realm β β β Realm Controller β ββ
β β - Client β β ββββββββββββββββββββββββββββββ€ ββ
β β - User β β β Client Controller β ββ
β β - ... β β ββββββββββββββββββββββββββββββ€ ββ
β βββββββββββββββββββ β β User Controller β ββ
β β ββββββββββββββββββββββββββββββ ββ
β ββββββββββββββββ¬βββββββββββββββββββββ
β β β
β βΌ β
β βββββββββββββββββββββββββββββββββββββ
β β Keycloak Server ββ
β β (Admin REST API) ββ
β βββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
keycloak-operator/
βββ api/
β βββ v1beta1/ # API types (CRDs)
βββ cmd/
β βββ main.go # Operator entrypoint
βββ internal/
β βββ controller/ # Reconciliation logic
β βββ keycloak/ # Keycloak client wrapper
βββ config/
β βββ crd/ # CRD manifests
β βββ manager/ # Operator deployment
β βββ rbac/ # RBAC configuration
β βββ samples/ # Example resources
βββ test/
β βββ e2e/ # End-to-end tests
βββ charts/
β βββ keycloak-operator/ # Helm chart
βββ hack/ # Development scripts
βββ Dockerfile
βββ Makefile
βββ go.mod
- Go 1.22+
- Docker
- kubectl
- Kind (
brew install kind) - Helm
# Install from OCI registry
helm install keycloak-operator oci://ghcr.io/hostzero-gmbh/charts/keycloak-operator \
--namespace keycloak-operator \
--create-namespace# Create Kind cluster with Keycloak and operator deployed
make kind-all
# Check operator logs
make kind-logs
# Apply sample resources
kubectl apply -f config/samples/
# After code changes, rebuild and restart the operator
make kind-redeploy# Run unit tests (fast, no cluster required)
make test
# Run full E2E tests (requires Kind cluster with operator deployed)
make kind-test-run
# Run a specific E2E test
make kind-test-run TEST_RUN=TestKeycloakRealmE2EThe operator exposes Prometheus metrics at :8080/metrics and optional OpenTelemetry (OTLP) traces and logs:
- Reconciliation metrics: Total reconciliations, duration, errors by controller
- Resource metrics: Managed and ready resources by type
- Keycloak connection: Connection status, API request counts and latency
- Traces: Root span per reconcile plus Keycloak Admin API calls (opt-in via
otel.enabled)
Key alerts to configure:
- Connection failures (
keycloak_operator_keycloak_connection_status == 0) - High error rate (>10% reconciliation failures)
- Resources not ready for extended periods
See the Monitoring Documentation for detailed metrics reference, alerting rules, and Grafana dashboard recommendations.
Defines a connection to a Keycloak server.
apiVersion: keycloak.hostzero.com/v1beta1
kind: KeycloakInstance
metadata:
name: keycloak-instance
spec:
baseUrl: http://keycloak:8080
auth:
passwordGrant:
secretRef:
name: keycloak-admin
usernameKey: username
passwordKey: passwordDefines a realm within a Keycloak instance.
apiVersion: keycloak.hostzero.com/v1beta1
kind: KeycloakRealm
metadata:
name: my-realm
spec:
instanceRef: keycloak-instance
definition:
realm: my-realm
displayName: My Realm
enabled: trueDefines an OIDC or SAML client within a realm.
apiVersion: keycloak.hostzero.com/v1beta1
kind: KeycloakClient
metadata:
name: my-client
spec:
realmRef:
name: my-realm
definition:
clientId: my-client
name: My Application
publicClient: false
standardFlowEnabled: true
clientSecretRef:
name: my-client-secretThis operator is developed and maintained by Hostzero GmbH, a provider of sovereign IT infrastructure solutions.
For organizations with critical infrastructure needs (KRITIS), we offer:
- Enterprise support with SLAs
- Security hardening and compliance consulting
- On-premises deployment assistance
- 24/7 incident response
- Training and workshops
Contact us for enterprise licensing and support options.
The operator is also distributed as an OLM bundle via two community catalogs:
- OperatorHub.io (
k8s-operatorhub/community-operators), used by plain Kubernetes clusters. - The OpenShift/OKD community catalog (
redhat-openshift-ecosystem/community-operators-prod), which ships pre-configured in every OpenShift and OKD cluster's embedded OperatorHub.
New versions are published by:
- Tagging a release (
vX.Y.Z) so the regularReleaseworkflow ships the controller image and Helm chart. - Running the
Publish to OperatorHub catalogsworkflow manually (Actions β Publish to OperatorHub catalogs β Run workflow) with the same version. Thetargetinput selectsall(default),operatorhuboropenshift.
The workflow regenerates the OLM bundle once (make bundle) with the controller image pinned to the digest of the released tag (required for disconnected installs via oc-mirror), then for each target copies it into a fork of the catalog repo and opens a PR upstream. Both catalogs run in semver mode, so the upgrade graph is derived from version numbers and the workflow strips spec.replaces from the CSV.
Upstream PRs merge automatically once their CI passes, as long as the PR author is listed under reviewers in operators/hostzero-keycloak-operator/ci.yaml on the catalog's main branch. The first PR to a catalog ships that file (from hack/olm/ci.yaml) together with the first bundle version and is merged manually by the upstream maintainers after CI is green.
Prerequisites:
- Forks of both catalog repos (
community-operatorsandcommunity-operators-prod) under theOPERATORHUB_FORK_OWNERaccount. OPERATORHUB_PATsecret β classic PAT with thepublic_repoandworkflowscopes, owned by a user listed inci.yaml. A fine-grained PAT does not work here: opening a PR against the upstream catalog repos calls a GraphQL mutation on those repos, which fine-grained tokens cannot be authorised for (they can only grant permissions on repos owned by the token's account).workflowis needed because syncing the fork with upstreammainpushes upstream's.github/workflowsfiles.OPERATORHUB_FORK_OWNERsecret β owner of the forks (defaults to the org running the workflow).
To regenerate the bundle locally:
make bundle VERSION=0.8.0
./bin/operator-sdk bundle validate ./bundle --select-optional name=operatorhubContributions are welcome! Please read our Contributing Guide for details on our development process and how to submit pull requests.
For security concerns, please see our Security Policy.
MIT License - see LICENSE for details.