keycloak-operator

by somaz94

Helm chartv0.2.8App 26.8.2Apache-2.0Verified publisher

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

ResourceAPIPurpose
CustomResourceDefinition (Keycloak)apiextensions.k8s.io/v1Defines k8s.keycloak.org/v2beta1 Keycloak CR.
CustomResourceDefinition (KeycloakRealmImport)apiextensions.k8s.io/v1Defines k8s.keycloak.org/v2beta1 KeycloakRealmImport CR.
CustomResourceDefinition (KeycloakOIDCClient)apiextensions.k8s.io/v1Defines k8s.keycloak.org/v2alpha1 KeycloakOIDCClient CR (added in operator 26.7.0).
CustomResourceDefinition (KeycloakSAMLClient)apiextensions.k8s.io/v1Defines k8s.keycloak.org/v2alpha1 KeycloakSAMLClient CR (added in operator 26.7.0).
ServiceAccount (keycloak-operator)v1Operator identity.
ClusterRole (×5)rbac.authorization.k8s.io/v1OpenShift ingresses read; keycloaks, keycloakrealmimports, keycloakoidcclients, keycloaksamlclients controllers.
ClusterRoleBindingrbac.authorization.k8s.io/v1Binds the operator SA to the OpenShift-ingresses read role cluster-wide.
RoleBinding (×5)rbac.authorization.k8s.io/v1Binds the four controller ClusterRoles in the release namespace (ClusterRoleBinding instead when rbac.useClusterBindings: true), plus view access.
Service (keycloak-operator)v1Health/metrics endpoint on port 80 → 8080.
Deployment (keycloak-operator)apps/v1One operator pod with liveness/readiness/startup probes against /q/health/*.

Versioning

FieldMeaning
Chart.yaml versionThe chart's own SemVer. Bumped manually via make bump CHART=keycloak-operator LEVEL=patch|minor|major for template/schema changes.
Chart.yaml appVersionThe pinned Keycloak Operator release (and Keycloak server image tag). Tracked by upgrade.sh against keycloak/keycloak-k8s-resources.
values.yaml versionIdentical 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 serviceMonitor reconciliation 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

KeyTypeDefaultDescription
versionstringmatches appVersionPinned upstream version. Drives the default image tag and RELATED_IMAGE_KEYCLOAK. Rewritten by upgrade.sh.
commonLabelsobject{}Labels added to every resource.
commonAnnotationsobject{}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

KeyTypeDefaultDescription
image.repositorystringquay.io/keycloak/keycloak-operatorOperator image repository.
image.tagstring""Image tag. Empty → uses .Values.version.
image.pullPolicystringIfNotPresentAlways, IfNotPresent, or Never.
serverImage.repositorystringquay.io/keycloak/keycloakKeycloak server image repository (RELATED_IMAGE_KEYCLOAK).
serverImage.tagstring""Empty → uses .Values.version.
imagePullSecrets[]list[]Pull secrets attached to the operator Pods.

Deployment

KeyTypeDefaultDescription
replicasint1Operator replicas. The operator does not support active-active — keep at 1 unless using leader election.
resourcesobject{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, securityContextobject{}Pod template metadata + security contexts.
extraEnv[]list[]Additional env vars (chart already wires KUBERNETES_NAMESPACE, RELATED_IMAGE_KEYCLOAK, watch-scope vars).
watchNamespacesstringJOSDK_WATCH_CURRENTJOSDK_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}objectupstream defaultsProbe knobs.
volumes, volumeMountslist[]Operator container volumes.
deploymentExtraobject{}Escape hatch. Merged into Deployment.spec.
containerExtraobject{}Escape hatch. Merged into the operator container spec.

Service / ServiceAccount / RBAC / CRDs

KeyTypeDefaultDescription
service.enabledbooltrueRender the operator Service (health/metrics on port 80 → 8080).
service.type, .port, .targetPort, .name, .annotations, .labels——Standard Service knobs.
serviceAccount.createbooltrueRender the SA. Disable to wire an externally-managed SA.
serviceAccount.namestringkeycloak-operatorSA name. The Deployment references this.
rbac.createbooltrueRender ClusterRole / ClusterRoleBinding / RoleBinding.
rbac.subjectNamespacestring"" (= Release.Namespace)Namespace used as the ClusterRoleBinding subject's namespace. Override only when SA lives in a different namespace from the chart release.
rbac.useClusterBindingsboolfalseBind 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.installbooltrueRender the four CRDs in templates/. Disable when CRDs are managed externally.
crds.keepbooltrueAdd 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:

  1. Verifies quay.io/keycloak/keycloak-operator:<version> exists.
  2. Backs up Chart.yaml, values.yaml, the CRD templates and upstream/kubernetes.yml to backup/<timestamp>/.
  3. 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.
  4. Saves the upstream kubernetes/kubernetes.yml from the same tag to upstream/kubernetes.yml (not packaged; see .helmignore).
  5. Rewrites Chart.yaml appVersion and values.yaml version.
  6. Resets artifacthub.io/changes to a single kind: changed entry (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.yaml version) — run make bump CHART=keycloak-operator LEVEL=patch after reviewing the diff.
  • Refresh templates/deployment.yaml / rbac.yaml / service.yaml — those are chart-managed re-implementations of kubernetes.yml.
    • RBAC is gated: make validate (and therefore CI) fails when any ClusterRole / Role the chart renders differs from upstream/kubernetes.yml rule for rule (scripts/validate/check-upstream-rbac.sh). Fix templates/rbac.yaml until it passes.
    • Everything else is manual: the gate does not compare bindings, the ServiceAccount, the Deployment or the Service. Review the upstream/kubernetes.yml diff after every bump, patch releases included, for changes such as a new env var, probe or binding.

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.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartkeycloak-operator is pinned at v0.2.8 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. 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