keycloak
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:
- MariaDB Operator (Recommended): Uses the official mariadb-operator to manage MariaDB instances
- 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
| Parameter | Default | Description |
|---|---|---|
replicaCount | 1 | Number of Keycloak replicas (use >1 for clustering) |
image.repository | quay.io/keycloak/keycloak | Official Keycloak container image |
image.tag | see values.yaml for value | Keycloak version |
image.pullPolicy | IfNotPresent | Image pull policy |
admin.username | admin | Keycloak admin username |
admin.password | admin | Keycloak admin password (change in production!) |
updateStrategy | RollingUpdate | StatefulSet update strategy |
Keycloak Configuration
| Parameter | Default | Description |
|---|---|---|
keycloak.proxy.headers | xforwarded | Proxy headers mode (xforwarded, forwarded) |
keycloak.hostname.strict | false | Enable strict hostname verification. Keep false to serve the same instance on multiple domains in parallel |
keycloak.cache.type | ispn | Cache 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.
| Parameter | Default | Description |
|---|---|---|
themes.enabled | false | Enable themes support |
themes.persistence.storageClass | `` | Storage Class for storing themes |
themes.persistence.accessMode | ReadWriteMany | Enable themes support |
themes.persistence.size | 1Gi | Size of themes volume |
themes.existingClaim | `` | Use existing volume instead of creating new pvc |
themes.sidecar.enabled | false | Start sidecar container inside keycloak pod for easyer theme management |
themes.sidecar.image | alpine:latest | Image of sidecar container |
themes.sidecar.pullPolicy | IfNotPresent | Image of sidecar container |
themes.sidecar.resources | see values.yaml for defaults | Limit ressources for sidecar container |
themes.sidecar.securityContext | {} | Security context of sidecar container |
Database Configuration - MariaDB Operator
| Parameter | Default | Description |
|---|---|---|
mariadbOperator.enabled | false | Enable MariaDB Operator integration |
mariadbOperator.database | keycloak | Database name to create |
mariadbOperator.username | keycloak | Database username to create |
mariadbOperator.password | keycloakpass | Database password |
mariadbOperator.storageClass | longhorn | Storage class for MariaDB |
mariadbOperator.useExisting.enabled | false | Use existing MariaDB instance |
mariadbOperator.useExisting.namespace | - | Namespace of existing MariaDB |
mariadbOperator.useExisting.mariaDbRef | - | Name of existing MariaDB CR |
Database Configuration - External Database
| Parameter | Default | Description |
|---|---|---|
database.type | mariadb | Database type (mariadb, postgres) |
database.name | keycloak | Database name |
database.username | keycloak | Database username |
database.password | keycloakpass | Database password |
database.host | "" | Database host (auto-set with operator) |
database.port | 3306 | Database port |
database.dbUrl | 3306 | Database db url |
Service Configuration
| Parameter | Default | Description |
|---|---|---|
service.type | ClusterIP | Service type |
service.port | 8080 | Service port |
Ingress Configuration
| Parameter | Default | Description |
|---|---|---|
ingress.enabled | false | Enable Ingress |
ingress.className | "" | Ingress class name (e.g., nginx) |
ingress.annotations | {} | Ingress annotations |
ingress.hosts | See values.yaml | Ingress 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.
| Parameter | Default | Description |
|---|---|---|
adminIngress.enabled | false | Enable 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.hosts | See values.yaml | Admin ingress hosts configuration |
adminIngress.tls | [] | TLS configuration |
Gateway API Configuration
| Parameter | Default | Description |
|---|---|---|
httpRoute.enabled | false | Enable GW API httpRoute |
httpRoute.annotations | {} | http Route annotations |
httpRoute.hostnames | [keycloak.example.com] | Public hostname(s) — multiple domains supported |
httpRoute.parentRefs | See values.yaml | httproute parent ref |
httpRoute.matches | See values.yaml | Match 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.
| Parameter | Default | Description |
|---|---|---|
adminHttpRoute.enabled | false | Enable the dedicated admin HTTPRoute |
adminHttpRoute.annotations | {} | http Route annotations |
adminHttpRoute.hostnames | {hostnames: [keycloak-admin.example.com]} | Admin hostname |
adminHttpRoute.parentRefs | See values.yaml | httproute parent ref (e.g. an internal Gateway) |
adminHttpRoute.matches | See values.yaml | Match 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/httpRouteonly routes an allow-list of paths. The defaults are the exact set Keycloak recommends exposing behind a reverse proxy:/realms,/resourcesand/.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 return404on the public host(s). - The dedicated
adminIngress/adminHttpRouteroute/(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:
/metricsand/healthare not in the allow-list either, but this chart already serves them on the separate management port9000(not on the8080service 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/adminis 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
| Parameter | Default | Description |
|---|---|---|
livenessProbe.httpGet.path | /health/live | Liveness probe path |
livenessProbe.httpGet.port | 9000 | Liveness probe port |
livenessProbe.periodSeconds | 10 | Probe check interval |
readinessProbe.httpGet.path | /health/ready | Readiness probe path |
readinessProbe.httpGet.port | 9000 | Readiness probe port |
readinessProbe.periodSeconds | 10 | Probe 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.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartkeycloak is pinned at v0.2.38 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