keycloak

by Syntax3rror404

Helm chartv0.2.38App 26.8.2Verified publisher

A Helm chart which provides rootless keycloak with mariadb-operator and multi replica support

About this chart

helm-charts/keycloak

Keycloak is an open source Identity and Access Management solution aimed at modern applications and services. It makes it easy to secure applications and services with little to no code.

Introduction

This Helm chart deploys Keycloak on Kubernetes using the official Keycloak container image from quay.io/keycloak/keycloak.

It also provides a sidecar container for easyer managing custom keycloak themes.

Database Options

The chart supports two database configuration methods:

  1. MariaDB Operator (Recommended): Uses the official mariadb-operator to manage MariaDB instances
  2. External Database: Connect to an existing database outside of this chart

Important: The MariaDB Operator must be pre-installed on your Kubernetes cluster if you choose option 1.

In short:

helm repo add mariadb-operator https://helm.mariadb.com/mariadb-operator
helm install mariadb-operator-crds mariadb-operator/mariadb-operator-crds
helm install mariadb-operator mariadb-operator/mariadb-operator

Key Features

  • Official Keycloak image from Quay.io
  • Custom theme support with sidecar container support to provide easyer theme installations
  • Automatic admin credentials management via Kubernetes secrets
  • Supports both new MariaDB instances and existing MariaDB deployments managed by the operator
  • StatefulSet deployment for clustering and data consistency
  • Infinispan clustering support with JGroups for multi-replica deployments
  • Optional Ingress configuration with proxy header support
  • Health probes for high availability
  • Headless service for clustering communication

Prerequisites

  • Kubernetes 1.19+
  • Helm 3.0+
  • MariaDB Operator installed (if using mariadbOperator.enabled: true)
    • Installation guide: https://github.com/mariadb-operator/mariadb-operator

Installation

HTTPS

helm repo add syntax3rror404 https://syntax3rror404.github.io/helm-charts/charts
helm repo update
helm install keycloak syntax3rror404/keycloak -n keycloak --create-namespace -f myvalues.yaml

OCI

helm install keycloak oci://ghcr.io/syntax3rror404/helm-charts/keycloak --version <version> -n keycloak --create-namespace -f myvalues.yaml

Note: A simple install uses default values like admin/admin for credentials. You must create your own values file for production use.

Upgrade

helm upgrade keycloak syntax3rror404/keycloak -n keycloak

Note: The admin credentials are stored as secrets and will be preserved during upgrades.

Uninstall

# Remove the Helm release
helm uninstall keycloak -n keycloak

# Delete the namespace (optional - this will remove all resources including PVCs)
kubectl delete ns keycloak

Configuration

Core Configuration Values

ParameterDefaultDescription
replicaCount1Number of Keycloak replicas (use >1 for clustering)
image.repositoryquay.io/keycloak/keycloakOfficial Keycloak container image
image.tagsee values.yaml for valueKeycloak version
image.pullPolicyIfNotPresentImage pull policy
admin.usernameadminKeycloak admin username
admin.passwordadminKeycloak admin password (change in production!)
updateStrategyRollingUpdateStatefulSet update strategy

Keycloak Configuration

ParameterDefaultDescription
keycloak.proxy.headersxforwardedProxy headers mode (xforwarded, forwarded)
keycloak.hostname.strictfalseEnable strict hostname verification. Keep false to serve the same instance on multiple domains in parallel
keycloak.cache.typeispnCache type (ispn for clustering, local for single node)
keycloak.args["start"]Keycloak args list
keycloak.httpPath"/"Keycloak used http path

Themes Configuration

This sidecar container allows you to manage keycloak themes e.g to use kubectl cp to copy a theme to the theme volume, because the keycloak container does not contain any binaries like tar etc.

After the theme installation you can disable the sidecar afterwards.

The volume is mounted to /themes.

After the installation of the theme you can enable the theme inside the realm settings.

ParameterDefaultDescription
themes.enabledfalseEnable themes support
themes.persistence.storageClass``Storage Class for storing themes
themes.persistence.accessModeReadWriteManyEnable themes support
themes.persistence.size1GiSize of themes volume
themes.existingClaim``Use existing volume instead of creating new pvc
themes.sidecar.enabledfalseStart sidecar container inside keycloak pod for easyer theme management
themes.sidecar.imagealpine:latestImage of sidecar container
themes.sidecar.pullPolicyIfNotPresentImage of sidecar container
themes.sidecar.resourcessee values.yaml for defaultsLimit ressources for sidecar container
themes.sidecar.securityContext{}Security context of sidecar container

Database Configuration - MariaDB Operator

ParameterDefaultDescription
mariadbOperator.enabledfalseEnable MariaDB Operator integration
mariadbOperator.databasekeycloakDatabase name to create
mariadbOperator.usernamekeycloakDatabase username to create
mariadbOperator.passwordkeycloakpassDatabase password
mariadbOperator.storageClasslonghornStorage class for MariaDB
mariadbOperator.useExisting.enabledfalseUse existing MariaDB instance
mariadbOperator.useExisting.namespace-Namespace of existing MariaDB
mariadbOperator.useExisting.mariaDbRef-Name of existing MariaDB CR

Database Configuration - External Database

ParameterDefaultDescription
database.typemariadbDatabase type (mariadb, postgres)
database.namekeycloakDatabase name
database.usernamekeycloakDatabase username
database.passwordkeycloakpassDatabase password
database.host""Database host (auto-set with operator)
database.port3306Database port
database.dbUrl3306Database db url

Service Configuration

ParameterDefaultDescription
service.typeClusterIPService type
service.port8080Service port

Ingress Configuration

ParameterDefaultDescription
ingress.enabledfalseEnable Ingress
ingress.className""Ingress class name (e.g., nginx)
ingress.annotations{}Ingress annotations
ingress.hostsSee values.yamlIngress hosts configuration
ingress.tls[]TLS configuration

Admin Ingress Configuration

Dedicated ingress for the admin console / admin REST endpoints (incl. the master realm). See Separating the admin console / master realm.

ParameterDefaultDescription
adminIngress.enabledfalseEnable the dedicated admin Ingress
adminIngress.className""Ingress class name (e.g. an internal-only class)
adminIngress.annotations{}Ingress annotations (e.g. IP allow-lists)
adminIngress.hostsSee values.yamlAdmin ingress hosts configuration
adminIngress.tls[]TLS configuration

Gateway API Configuration

ParameterDefaultDescription
httpRoute.enabledfalseEnable GW API httpRoute
httpRoute.annotations{}http Route annotations
httpRoute.hostnames[keycloak.example.com]Public hostname(s) — multiple domains supported
httpRoute.parentRefsSee values.yamlhttproute parent ref
httpRoute.matchesSee values.yamlMatch configuration

Admin Gateway API Configuration

Dedicated HTTPRoute for the admin console / admin REST endpoints (incl. the master realm). See Separating the admin console / master realm.

ParameterDefaultDescription
adminHttpRoute.enabledfalseEnable the dedicated admin HTTPRoute
adminHttpRoute.annotations{}http Route annotations
adminHttpRoute.hostnames{hostnames: [keycloak-admin.example.com]}Admin hostname
adminHttpRoute.parentRefsSee values.yamlhttproute parent ref (e.g. an internal Gateway)
adminHttpRoute.matchesSee values.yamlMatch configuration

Separating the admin console / master realm

By default Keycloak serves the admin console (and therefore the master realm) on the same path space as the public authentication endpoints, so exposing your public host also exposes the admin surface. This chart separates them at the path level instead of pinning a fixed hostname — which means no KC_HOSTNAME is baked in and the same instance can be served on multiple public domains in parallel.

How it works:

  • The public ingress / httpRoute only routes an allow-list of paths. The defaults are the exact set Keycloak recommends exposing behind a reverse proxy: /realms, /resources and /.well-known. That is everything a login/OIDC flow needs (auth endpoints + the login UI's assets + authorization-server metadata). Keycloak explicitly recommends not exposing / (welcome page) and /admin (admin console + admin REST, incl. the master realm) — neither is in the list, so both return 404 on the public host(s).
  • The dedicated adminIngress / adminHttpRoute route / (the whole instance, including /admin) on a separate, internal-only host that you can lock down with an internal ingress class / Gateway, an IP allow-list, or a separate TLS certificate.

To expose the admin console on the public host as well, simply add /admin to ingress.hosts[].paths / httpRoute.matches.

Note: /metrics and /health are not in the allow-list either, but this chart already serves them on the separate management port 9000 (not on the 8080 service that the ingress points at), so they are never reachable through the public ingress regardless.

Example: public + separate admin ingress (nginx, internal-only)

# Public ingress: multiple domains, admin surface excluded via paths
ingress:
  enabled: true
  className: nginx
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt-prod
  hosts:
    - host: auth.mycompany.com
      paths: &publicPaths
        - path: /realms
          pathType: Prefix
        - path: /resources
          pathType: Prefix
        - path: /.well-known
          pathType: Prefix
    - host: login.othertenant.com   # parallel domain, same instance
      paths: *publicPaths
  tls:
    - secretName: keycloak-tls
      hosts:
        - auth.mycompany.com
        - login.othertenant.com

# Admin ingress: internal host, serves the whole instance incl. /admin
adminIngress:
  enabled: true
  className: nginx
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt-prod
    nginx.ingress.kubernetes.io/whitelist-source-range: "10.0.0.0/8"
  hosts:
    - host: keycloak-admin.internal.mycompany.com
      paths:
        - path: /
          pathType: Prefix
  tls:
    - secretName: keycloak-admin-tls
      hosts:
        - keycloak-admin.internal.mycompany.com

Example: public + separate admin HTTPRoute (Gateway API)

httpRoute:
  enabled: true
  hostnames:
    - auth.mycompany.com
    - login.othertenant.com   # parallel domain, same instance
  parentRefs:
    - group: gateway.networking.k8s.io
      kind: Gateway
      name: envoy-gateway-external
      namespace: envoy-gateway-system
  matches:
    - path: { type: PathPrefix, value: /realms }
    - path: { type: PathPrefix, value: /resources }
    - path: { type: PathPrefix, value: /.well-known }

adminHttpRoute:
  enabled: true
  hostnames:
    - keycloak-admin.internal.mycompany.com
  parentRefs:
    - group: gateway.networking.k8s.io
      kind: Gateway
      name: envoy-gateway-internal
      namespace: envoy-gateway-system
  matches:
    - path: { type: PathPrefix, value: / }

Note on /realms/master: The path allow-list blocks the admin console (/admin). The master realm's own OIDC endpoints live under /realms/master, which is a sub-path of the allow-listed /realms — plain Ingress/Gateway prefix matching can't exclude a single sub-path, so those endpoints stay reachable on the public host. This is low risk once /admin is blocked (no admin console to drive them, and Keycloak's brute-force protection still applies). If you need to block them too, use a controller-specific deny rule, e.g. for nginx:

ingress:
  annotations:
    nginx.ingress.kubernetes.io/server-snippet: |
      location ~* "^/realms/master" { return 404; }

Health Probes

ParameterDefaultDescription
livenessProbe.httpGet.path/health/liveLiveness probe path
livenessProbe.httpGet.port9000Liveness probe port
livenessProbe.periodSeconds10Probe check interval
readinessProbe.httpGet.path/health/readyReadiness probe path
readinessProbe.httpGet.port9000Readiness probe port
readinessProbe.periodSeconds10Probe check interval

Configuration Examples

Example 1: Single Instance with New MariaDB

# myvalues.ya

Deploy keycloak with OpenTenant

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