keycloak-operator
by somaz94
Keycloak Operator install (CRDs + Deployment + RBAC + Service) wrapped from the upstream keycloak-k8s-resources raw YAML. Pin upstream releases via upgrade.sh; operate Keycloak instances with the keycloak-cr chart.
About this chart
keycloak-operator
A Helm chart that wraps the upstream Keycloak Operator raw YAML — published by the Keycloak project at keycloak/keycloak-k8s-resources under kubernetes/.
The Keycloak project does not ship a Helm chart for the operator (only the raw kubernetes.yml and the CRDs). This chart packages those manifests, makes the namespace, image, watch-scope and resource limits configurable, and ships an upgrade.sh that tracks new keycloak-k8s-resources tags and refreshes the in-tree CRD templates.
After installing this chart, use the keycloak-cr chart to render Keycloak instances (Keycloak, KeycloakRealmImport CRs).
What it deploys
| Resource | API | Purpose |
|---|---|---|
CustomResourceDefinition (Keycloak) | apiextensions.k8s.io/v1 | Defines k8s.keycloak.org/v2beta1 Keycloak CR. |
CustomResourceDefinition (KeycloakRealmImport) | apiextensions.k8s.io/v1 | Defines k8s.keycloak.org/v2beta1 KeycloakRealmImport CR. |
CustomResourceDefinition (KeycloakOIDCClient) | apiextensions.k8s.io/v1 | Defines k8s.keycloak.org/v2alpha1 KeycloakOIDCClient CR (added in operator 26.7.0). |
CustomResourceDefinition (KeycloakSAMLClient) | apiextensions.k8s.io/v1 | Defines k8s.keycloak.org/v2alpha1 KeycloakSAMLClient CR (added in operator 26.7.0). |
ServiceAccount (keycloak-operator) | v1 | Operator identity. |
ClusterRole (×5) | rbac.authorization.k8s.io/v1 | OpenShift ingresses read; keycloaks, keycloakrealmimports, keycloakoidcclients, keycloaksamlclients controllers. |
ClusterRoleBinding | rbac.authorization.k8s.io/v1 | Binds the operator SA to the OpenShift-ingresses read role cluster-wide. |
RoleBinding (×5) | rbac.authorization.k8s.io/v1 | Binds the four controller ClusterRoles in the release namespace (ClusterRoleBinding instead when rbac.useClusterBindings: true), plus view access. |
Service (keycloak-operator) | v1 | Health/metrics endpoint on port 80 → 8080. |
Deployment (keycloak-operator) | apps/v1 | One operator pod with liveness/readiness/startup probes against /q/health/*. |
Versioning
| Field | Meaning |
|---|---|
Chart.yaml version | The chart's own SemVer. Bumped manually via make bump CHART=keycloak-operator LEVEL=patch|minor|major for template/schema changes. |
Chart.yaml appVersion | The pinned Keycloak Operator release (and Keycloak server image tag). Tracked by upgrade.sh against keycloak/keycloak-k8s-resources. |
values.yaml version | Identical to appVersion by default. Used to render the operator image tag and the RELATED_IMAGE_KEYCLOAK env value when image.tag / serverImage.tag are left empty. |
Prerequisites
- Kubernetes 1.25+
- Permission to create cluster-scoped resources (CRDs,
ClusterRole,ClusterRoleBinding). - For
serviceMonitorreconciliation by the operator, the Prometheus Operator installed (Keycloak CRs can opt into ServiceMonitor creation).
Install
These snippets install the latest published chart. To pin an exact chart version, add --version <x.y.z> — released versions are the GitHub Release tags named keycloak-operator-<version>.
OCI registry (Helm 3.8+)
helm install keycloak-operator oci://ghcr.io/somaz94/charts/keycloak-operator \
--namespace keycloak-system --create-namespace
Classic Helm repo
helm repo add somaz94 https://charts.somaz.blog
helm repo update
helm install keycloak-operator somaz94/keycloak-operator \
--namespace keycloak-system --create-namespace
Quick examples
1. Default install (watch own namespace)
helm install keycloak-operator oci://ghcr.io/somaz94/charts/keycloak-operator \
-n keycloak-system --create-namespace
The operator only reconciles Keycloak / KeycloakRealmImport CRs in the keycloak-system namespace. Subsequently, install the keycloak-cr chart in keycloak-system (or set watchNamespaces below to a different scope).
2. Watch every namespace cluster-wide
watchNamespaces: JOSDK_ALL_NAMESPACES
rbac:
useClusterBindings: true # required for any cross-namespace watch
helm install keycloak-operator oci://ghcr.io/somaz94/charts/keycloak-operator \
-n keycloak-system --create-namespace -f values.yaml
3. Watch a specific list of namespaces
watchNamespaces: "tenant-a,tenant-b"
rbac:
useClusterBindings: true # required when the list spans namespaces other than the release ns
4. Air-gapped / private registry (override images)
image:
repository: registry.internal.example.com/keycloak/keycloak-operator
tag: <operator-tag> # operator image (defaults to .Values.version)
pullPolicy: IfNotPresent
serverImage:
repository: registry.internal.example.com/keycloak/keycloak
tag: <server-tag> # rendered into RELATED_IMAGE_KEYCLOAK env
imagePullSecrets:
- name: registry-internal-pull
5. CRDs managed externally (chart only installs operator)
crds:
install: false # CRDs registered out-of-band (e.g. fleet GitOps)
When this flag is off, the chart skips all four CRDs — the operator still references them, so keycloaks.k8s.keycloak.org, keycloakrealmimports.k8s.keycloak.org, keycloakoidcclients.k8s.keycloak.org, and keycloaksamlclients.k8s.keycloak.org must be present in the cluster before this chart is applied.
Values reference
The tables below mirror values.yaml, which is authoritative; values.schema.json enforces the shape.
Top-level
| Key | Type | Default | Description |
|---|---|---|---|
version | string | matches appVersion | Pinned upstream version. Drives the default image tag and RELATED_IMAGE_KEYCLOAK. Rewritten by upgrade.sh. |
commonLabels | object | {} | Labels added to every resource. |
commonAnnotations | object | {} | Annotations added to every resource. |
resourceMetadata.<resource>.{labels,annotations} | object | {} | Per-resource overrides. Resources: serviceAccount, deployment, service, clusterRoles, roleBinding, clusterRoleBindings. role is deprecated and ignored since 0.2.7 (no Role is rendered). |
Image
| Key | Type | Default | Description |
|---|---|---|---|
image.repository | string | quay.io/keycloak/keycloak-operator | Operator image repository. |
image.tag | string | "" | Image tag. Empty → uses .Values.version. |
image.pullPolicy | string | IfNotPresent | Always, IfNotPresent, or Never. |
serverImage.repository | string | quay.io/keycloak/keycloak | Keycloak server image repository (RELATED_IMAGE_KEYCLOAK). |
serverImage.tag | string | "" | Empty → uses .Values.version. |
imagePullSecrets[] | list | [] | Pull secrets attached to the operator Pods. |
Deployment
| Key | Type | Default | Description |
|---|---|---|---|
replicas | int | 1 | Operator replicas. The operator does not support active-active — keep at 1 unless using leader election. |
resources | object | {cpu: 300m–700m, mem: 450Mi} | Compute resources. Defaults mirror the upstream operator manifests for the tracked appVersion. |
nodeSelector, tolerations, affinity, priorityClassName, topologySpreadConstraints | — | — | Standard pod-scheduling fields. |
podLabels, podAnnotations, podSecurityContext, securityContext | object | {} | Pod template metadata + security contexts. |
extraEnv[] | list | [] | Additional env vars (chart already wires KUBERNETES_NAMESPACE, RELATED_IMAGE_KEYCLOAK, watch-scope vars). |
watchNamespaces | string | JOSDK_WATCH_CURRENT | JOSDK_WATCH_CURRENT (own NS), JOSDK_ALL_NAMESPACES (cluster-wide), or ns-a,ns-b list. Anything other than JOSDK_WATCH_CURRENT requires rbac.useClusterBindings: true. |
probes.{liveness,readiness,startup} | object | upstream defaults | Probe knobs. |
volumes, volumeMounts | list | [] | Operator container volumes. |
deploymentExtra | object | {} | Escape hatch. Merged into Deployment.spec. |
containerExtra | object | {} | Escape hatch. Merged into the operator container spec. |
Service / ServiceAccount / RBAC / CRDs
| Key | Type | Default | Description |
|---|---|---|---|
service.enabled | bool | true | Render the operator Service (health/metrics on port 80 → 8080). |
service.type, .port, .targetPort, .name, .annotations, .labels | — | — | Standard Service knobs. |
serviceAccount.create | bool | true | Render the SA. Disable to wire an externally-managed SA. |
serviceAccount.name | string | keycloak-operator | SA name. The Deployment references this. |
rbac.create | bool | true | Render ClusterRole / ClusterRoleBinding / RoleBinding. |
rbac.subjectNamespace | string | "" (= Release.Namespace) | Namespace used as the ClusterRoleBinding subject's namespace. Override only when SA lives in a different namespace from the chart release. |
rbac.useClusterBindings | bool | false | Bind the per-controller cluster roles (keycloakcontroller-cluster-role, keycloakrealmimportcontroller-cluster-role, keycloakoidcclientcontroller-cluster-role, keycloaksamlclientcontroller-cluster-role) via ClusterRoleBinding instead of in-namespace RoleBinding. Required when watchNamespaces is anything other than JOSDK_WATCH_CURRENT — RoleBindings only grant their bound rules within their own namespace, so the operator cannot list/watch CRs in other namespaces otherwise. |
crds.install | bool | true | Render the four CRDs in templates/. Disable when CRDs are managed externally. |
crds.keep | bool | true | Add helm.sh/resource-policy: keep so the CRDs survive a chart uninstall. Recommended in production. |
Maintaining this chart
This chart wraps third-party YAML — the CRDs and the operator manifest evolve on the Keycloak release cadence. The chart-local upgrade.sh automates the bump:
cd charts/keycloak-operator
./upgrade.sh --dry-run # preview the next bump
./upgrade.sh # bump to the latest GA tag
./upgrade.sh --version 26.7.0 # pin to a specific tag
./upgrade.sh --rollback # restore from backup/<timestamp>/
./upgrade.sh --list-backups
./upgrade.sh --cleanup-backups # keep last 5 (override KEEP_BACKUPS=N)
What it does on a successful bump:
- Verifies
quay.io/keycloak/keycloak-operator:<version>exists. - Backs up
Chart.yaml,values.yaml, the CRD templates andupstream/kubernetes.ymltobackup/<timestamp>/. - Re-fetches the four upstream CRDs (
keycloaks,keycloakrealmimports,keycloakoidcclients,keycloaksamlclients.k8s.keycloak.org-v1.yml) from the upstream tag, re-injects the chart's{{- if .Values.crds.install }}gate and labels/annotations block. - Saves the upstream
kubernetes/kubernetes.ymlfrom the same tag toupstream/kubernetes.yml(not packaged; see.helmignore). - Rewrites
Chart.yamlappVersionandvalues.yamlversion. - Resets
artifacthub.io/changesto a singlekind: changedentry (the block describes only the release being cut).
What it does not do:
- Touch the cluster (no
kubectl,helm,helmfile). - Bump the chart's own SemVer (
Chart.yamlversion) — runmake bump CHART=keycloak-operator LEVEL=patchafter reviewing the diff. - Refresh
templates/deployment.yaml/rbac.yaml/service.yaml— those are chart-managed re-implementations ofkubernetes.yml.- RBAC is gated:
make validate(and therefore CI) fails when any ClusterRole / Role the chart renders differs fromupstream/kubernetes.ymlrule for rule (scripts/validate/check-upstream-rbac.sh). Fixtemplates/rbac.yamluntil it passes. - Everything else is manual: the gate does not compare bindings, the ServiceAccount, the Deployment or the Service. Review the
upstream/kubernetes.ymldiff after every bump, patch releases included, for changes such as a new env var, probe or binding.
- RBAC is gated:
License
Apache-2.0
Deploy keycloak-operator with OpenTenant
Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has keycloak-operator on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartkeycloak-operator is pinned at v0.2.8 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below opentenant validate opentenant.yaml terraform init && terraform apply