keycloak-cr

by somaz94

Helm chartv0.1.2App 1.0.0Apache-2.0Verified publisher

Custom resources (Keycloak, KeycloakRealmImport) for the Keycloak Operator, with optional HTTPRoute, DB-credentials Secret and bootstrap-admin Secret. Defaults to a single-instance Keycloak with edge-proxy mode.

About this chart

keycloak-cr

A Helm chart that renders the Keycloak Operator's custom resources (Keycloak, KeycloakRealmImport) plus a few convenience peripherals: HTTPRoute (Gateway API) or standalone Ingress, DB-credentials Secret, and a bootstrap-admin Secret.

This chart does not install the Keycloak Operator itself — install the keycloak-operator chart (or the upstream raw YAML) first so the CRDs and operator Deployment are present before this chart is applied.

What it deploys

ResourceAPIPurpose
Keycloakk8s.keycloak.org/v2beta1Primary CR — the operator reconciles a StatefulSet + Service from this. Always rendered.
KeycloakRealmImportk8s.keycloak.org/v2beta1Optional. One-shot Job that imports an inline RealmRepresentation.
HTTPRoutegateway.networking.k8s.io/v1Optional. Routes traffic from a Gateway to the Keycloak Service the operator renders.
HTTPRoute (https-redirect)gateway.networking.k8s.io/v1Optional. 301-redirects HTTP → HTTPS on the same hostname.
Ingressnetworking.k8s.io/v1Optional. Standalone Ingress when Gateway API is unavailable or finer control is needed than keycloak.ingress.
Secret (DB credentials)v1Optional. Convenience helper — render the username/password Secret inline rather than via ExternalSecrets.
Secret (bootstrap admin)v1Optional. Convenience helper — render the first-boot admin user/password.

Prerequisites

  • Kubernetes 1.25+
  • The Keycloak Operator installed (provides the Keycloak and KeycloakRealmImport CRDs and the controller Pod). Use the keycloak-operator chart from this repo, or the upstream raw YAML.
  • A reachable database (PostgreSQL recommended). The Keycloak Operator does not ship a database — bring your own. Most users pair this chart with the postgresql chart from this repo.
  • For httproute.enabled: true, Gateway API CRDs and a Gateway controller (e.g. NGINX Gateway Fabric).

Install

OCI registry (Helm 3.8+)

helm install keycloak oci://ghcr.io/somaz94/charts/keycloak-cr \
  --version 0.1.0 \
  --namespace keycloak \
  -f my-values.yaml

Classic Helm repo

helm repo add somaz94 https://charts.somaz.blog
helm repo update
helm install keycloak somaz94/keycloak-cr \
  --namespace keycloak \
  -f my-values.yaml

Quick examples

1. Minimal — single instance with an external DB Secret

The DB Secret already exists (created by the postgresql chart, ExternalSecrets, etc.). The chart only renders the Keycloak CR.

keycloak:
  instances: 1
  hostname:
    hostname: auth.example.com
    strict: true
  proxy:
    headers: xforwarded                  # behind a TLS-terminating gateway
  db:
    vendor: postgres
    host: keycloak-postgresql.keycloak.svc
    database: keycloak
    existingSecret: keycloak-db-credentials
    usernameSecretKey: username
    passwordSecretKey: password

2. Realm import — inline RealmRepresentation

Use this for small, declarative realms that fit comfortably in values.yaml. For exports larger than ~50 KB, prefer Example 3.

keycloak:
  hostname: { hostname: auth.example.com, strict: true }
  proxy: { headers: xforwarded }
  db:
    vendor: postgres
    host: keycloak-postgresql.keycloak.svc
    database: keycloak
    existingSecret: keycloak-db-credentials

realmImport:
  enabled: true
  realm:
    realm: acme
    enabled: true
    sslRequired: external
    registrationAllowed: false
    groups:
      - name: server
      - name: global-admin

3. Realm import — large export from a JSON file

The KeycloakRealmImport CRD only accepts the realm inline (spec.realm) — it does not natively read from a ConfigMap. For large kc.sh export outputs, use --set-file to inline the JSON at install time:

helm install keycloak oci://ghcr.io/somaz94/charts/keycloak-cr \
  -n keycloak -f values.yaml \
  --set realmImport.enabled=true \
  --set-file realmImport.realm=./realm-acme.json

For declarative GitOps (ArgoCD / Flux), commit the JSON, convert to YAML once, and embed it under realmImport.realm — Helm renders large YAML/JSON values without issue.

4. With HTTPRoute and chart-rendered DB Secret

End-to-end install: chart renders the DB Secret and an HTTPRoute attached to a shared Gateway. Suitable for dev / single-tenant clusters.

keycloak:
  instances: 1
  hostname: { hostname: auth.example.com, strict: true }
  proxy: { headers: xforwarded }
  db:
    vendor: postgres
    host: keycloak-postgresql.keycloak.svc
    database: keycloak
    # existingSecret left empty → chart-rendered Secret below is used

dbSecret:
  enabled: true
  username: keycloak
  password: REPLACE_ME         # rotate post-install

adminSecret:
  enabled: true
  username: admin
  password: REPLACE_ME         # rotate post-install via the admin UI

httproute:
  enabled: true
  parentRefs:
    - name: app
      namespace: nginx-gateway
      sectionName: https
  hostnames:
    - auth.example.com
  rules:
    - matches:
        - path: { type: PathPrefix, value: / }
      backendRefs:
        - port: 8080                   # name defaults to "<release>-service"
  httpsRedirect:
    enabled: true                      # 301 from the HTTP listener on the same Gateway

5. HA + escape hatch (specExtra)

For surfaces this chart does not surface explicitly (e.g. cache, httpManagement, imagePullSecrets on a non-default field), use the top-level escape hatch.

keycloak:
  instances: 3
  resources:
    requests: { cpu: "1", memory: 2Gi }
    limits:   { cpu: "2", memory: 4Gi }
  hostname: { hostname: auth.example.com, strict: true }
  proxy: { headers: xforwarded }
  db: { vendor: postgres, host: keycloak-postgresql.keycloak.svc, database: keycloak, existingSecret: keycloak-db-credentials }

  # mergeOverwrite semantics — anything below overrides chart-managed keys when keys collide.
  specExtra:
    cache:
      configMapFile:
        name: keycloak-cache-config
        key: cache-ispn.xml
    httpManagement:
      port: 9000

Values reference

Top-level

KeyTypeDefaultDescription
namestring""Override the chart-derived resource name (defaults to release name).
commonLabelsobject{}Labels added to every resource.
commonAnnotationsobject{}Annotations added to every resource.
resourceMetadata.<resource>.{labels,annotations}object{}Per-resource metadata override. Resources: keycloak, realmImport, httproute, ingress, dbSecret, adminSecret.

keycloak

KeyTypeDefaultDescription
instancesint1Number of Keycloak server pods. Use 2+ for HA (configure cache for distributed mode).
imagestring""Container image override. Empty → operator-default.
startOptimizedstring|bool"""true" / "false" / empty. Set only for pre-augmented custom images.
imagePullSecretslist[]Pull secrets attached to the server Pods.
hostname.hostnamestring""FQDN clients use to reach Keycloak. Required for proxy.headers != "" to avoid admin redirect loops.
hostname.adminstring""Optional separate admin hostname.
hostname.strictbooltrueDisable header-based hostname resolution.
hostname.backchannelDynamicboolfalseHostname v2 — enable for split private-network access.
http.httpEnabledbooltrueEnable plaintext HTTP listener (recommended behind TLS-terminating gateway).
http.httpPortint8080HTTP listener port.
http.httpsPortint8443HTTPS listener port.
http.tlsSecretstring""Secret for HTTPS termination at Keycloak (used when proxy=passthrough).
http.annotations / .labelsobject{}Operator-rendered Service metadata.
proxy.headersstring"""" / xforwarded / forwarded. Set when behind a TLS-terminating gateway.
db.vendorstringpostgresDB vendor (postgres, mariadb, mysql, mssql, oracle, h2).
db.host / .port / .database / .schema / .urlstring/intsee values.yamlConnection params. url overrides host/port/database.
db.existingSecretstring""Pre-existing Secret holding DB username + password. Falls back to chart-rendered dbSecret when both empty.
db.usernameSecretKey / .passwordSecretKeystringusername / passwordKeys inside the DB Secret.
db.poolMinSize / .poolInitialSize / .poolMaxSizeint0Connection pool sizing (0 = operator default).
bootstrapAdmin.userSecretstring""Pre-existing Secret with username + password. Falls back to chart-rendered adminSecret when both empty.
bootstrapAdmin.serviceSecretstring""Pre-existing Secret with client-id + client-secret.
resourcesobject{}Compute resources for the Keycloak server Pods.
schedulingobject{}Pod scheduling (nodeSelector, tolerations, affinity, priorityClassName, …).
features.enabled / .disabledlist[]Keycloak server feature flags.
ingress.enabledboolfalseOperator-rendered Ingress. Off by default — chart prefers HTTPRoute.
ingress.className / .annotations / .labels—"" / {}Standard Ingress metadata.
networkPolicy.enabledboolfalseOperator-rendered NetworkPolicy.
tracing.enabledboolfalseOpenTelemetry tracing.
tracing.endpoint / .protocol / .samplerType / .samplerRatio——Tracing config.
transaction.xaEnabledbool|nullnullForce XA / non-XA transactions. null = operator default.
truststoresobject{}Map of name → { secret, configMap } passed through to spec.truststores.
additionalOptionslist[]KC_* flag pass-through. Each entry: { name, value } or { name, secret: { name, key, optional } }.
envlist[]Env vars on Keycloak Pods (use additionalOptions for first-class flags).
specExtraobject{}Escape hatch. Merged into spec (top-level) of the Keycloak CR.

realmImport

KeyTypeDefaultDescription
enabledboolfalseRender a KeycloakRealmImport CR.
keycloakCRNamestring""Target Keycloak CR name. Defaults to this chart's main Keycloak CR.
realmobject{}Inline RealmRepresentation. The Keycloak CRD does not natively load from a ConfigMap — use --set-file realmImport.realm=path/to/realm.json for large exports.
placeholdersobject{}Realm import placeholder substitutions (typed as { secret: { name, key, optional } } per CRD).
resourcesobject{}Compute resources for the import Job (NOT for Keycloak itself).
specExtraobject{}Escape hatch merged into spec of the KeycloakRealmImport.

dbSecret / adminSecret

KeyTypeDefaultDescription
enabledboolfalseRender the convenience Secret.
namestring""Secret name. Defaults: <release>-db-credentials / <release>-bootstrap-admin.
username / passwordstring""Plaintext values rendered into the Secret. Rotate post-install or use ExternalSecrets / Vault.
usernameKey / passwordKeystringusername / passwordKeys inside the Secret.

ingress (chart-rendered, standalone Ingress)

Use this block when Gateway API is unavailable in the cluster, or when the operator's built-in keycloak.ingress field is too restrictive (no annotation control, single path, no TLS list). Mutually exclusive with httproute.enabled and keycloak.ingress.enabled — pick one routing method.

KeyTypeDefaultDescription
enabledboolfalseRender a standalone networking.k8s.io/v1 Ingress.
classNamestring""ingressClassName (e.g. nginx, traefik, alb).
hoststring""FQDN clients use to reach Keycloak.
path / pathTypestring/ / PrefixDefault rule path.
annotationsobject{}Ingress annotations (e.g. cert-manager, ALB target type, NGINX rewrite).
tls[]list[]TLS entries { hosts, secretName }.
backend.serviceName / .servicePortstring / intempty / 8080Backend Service override. Empty → operator-rendered <release>-service.
extraPaths[]list[]Additional paths on the same host (/admin, /metrics, …).

httproute

KeyTypeDefaultDescription
enabledboolfalseRender an HTTPRoute.
parentRefs[]list[]Gateway references ({ name, namespace, sectionName, port }).
hostnames[]list[]Hostnames matched on the parent Gateway.
rules[]listone defaultHTTPRoute rules. Backend defaults to <release>-service:8080.
httpsRedirect.enabledboolfalseRender a sibling HTTPRoute that 301-redirects HTTP → HTTPS.
httpsRedirect.statusCodeint301Redirect status.
httpsRedirect.parentRefs / .portlist / intempty / unsetOptional override (falls back to parentRefs and the Gateway's HTTPS port).

Notes

Operator dependency

The Keycloak Operator must be running in the cluster before this chart is applied — otherwise the CR will be admitted but not reconciled. The simplest install order:

# 1. Operator + CRDs
helm install keycloak-operator oci://ghcr.io/somaz94/charts/keycloak-opera

Deploy keycloak-cr with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has keycloak-cr 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-cr is pinned at v0.1.2 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