keycloak
by arieotech
Production-grade Keycloak IAM. HA clustering, PSA restricted-mode, JSON Schema validation, SOC2 and DPDP compliance defaults. Uses the official quay.io/keycloak/keycloak image.
About this chart
Keycloak
Production-grade Helm chart for Keycloak — the open-source IAM and SSO platform.
HA clustering · PSA restricted-mode · SOC2/DPDP defaults · JSON Schema validation · NetworkPolicy
Table of Contents
- Why this chart exists
- Prerequisites
- Installing the Chart
- Accessing Keycloak
- Uninstalling the Chart
- How HA clustering works
- Configuration
- Image
- Replicas and HA
- Admin credentials
- Database
- Database checker
- Proxy and hostname
- Ingress and TLS
- Cache / clustering
- Service
- Persistence
- Custom themes and providers
- Resources
- JVM options
- Probes
- ServiceAccount
- Pod scheduling
- Pod annotations and labels
- Realm import
- Extra env, volumes, and sidecars
- Generic secrets
- Keycloak features
- NetworkPolicy
- Metrics and monitoring
- SOC2 compliance
- DPDP compliance (India)
- Using External Secrets Operator
- Istio Ambient Mesh
- Performance tuning
- Testing
- Troubleshooting
- Upgrading
- Production checklist
- Support
Why this chart exists
The official Keycloak project chart has significant production gaps that block real-world deployments:
| Gap | Impact |
|---|---|
| No PSA restricted-mode support | readOnlyRootFilesystem: true crashes Keycloak at startup — Quarkus writes to /opt/keycloak/lib/quarkus/ on every cold start |
KC_HEALTH_ENABLED not set | All probes fail with "connection refused" on every fresh install |
| No NetworkPolicy | Pod networking is open by default; ingress controller and inter-pod clustering are unrestricted |
| No JSON Schema validation | Invalid values are silently ignored instead of rejected at install time |
| Management port not on main Service | Prometheus ServiceMonitors can't scrape /metrics; helm test pods can't reach /health/* |
| JGroups ports not updated | Clustering fails silently on Keycloak 25+ (ports changed from 7600 to 7800) |
| No SOC2/DPDP compliance defaults | Each team re-implements audit logging and PII masking from scratch |
| No E2E validation | Charts ship without any OIDC token-flow test |
This chart fixes all of the above and ships production defaults out of the box.
Prerequisites
- Kubernetes 1.27+
- Helm 3.12+
- PostgreSQL 15+ (external) —
bundled.enabledis available for development only - cert-manager (for TLS — recommended for production)
- Prometheus Operator (for ServiceMonitor — optional)
Installing the Chart
Add the Arieotech Helm repository:
helm repo add arieotech https://charts.arieotech.com
helm repo update
Minimal install (development):
helm install keycloak arieotech/keycloak \
--namespace keycloak \
--create-namespace \
--set keycloak.auth.adminPassword=changeme \
--set database.host=postgres.keycloak.svc.cluster.local \
--set database.password=changeme \
--set replicaCount=1 \
--set pdb.enabled=false \
--set networkPolicy.enabled=false
Production install (recommended pattern):
# Create secrets first
kubectl create namespace keycloak
kubectl create secret generic keycloak-admin \
--from-literal=admin-password=<strong-password> \
-n keycloak
kubectl create secret generic keycloak-db \
--from-literal=db-password=<strong-password> \
-n keycloak
# Install
helm install keycloak arieotech/keycloak \
--namespace keycloak \
--set keycloak.auth.existingSecret=keycloak-admin \
--set database.host=<postgres-host> \
--set database.existingSecret=keycloak-db \
--set dbchecker.enabled=true \
--set ingress.enabled=true \
--set ingress.className=nginx \
--set "ingress.hosts[0].host=keycloak.example.com" \
--set "ingress.hosts[0].paths[0].path=/" \
--set "ingress.hosts[0].paths[0].pathType=Prefix" \
--set "ingress.tls[0].secretName=keycloak-tls" \
--set "ingress.tls[0].hosts[0]=keycloak.example.com"
Dry-run to preview manifests:
helm install keycloak arieotech/keycloak \
--namespace keycloak \
--dry-run \
--set keycloak.auth.adminPassword=changeme \
--set database.host=postgres.example.com
Install from a values file:
helm install keycloak arieotech/keycloak \
--namespace keycloak \
-f my-values.yaml
Accessing Keycloak
Via Ingress (production):
Set ingress.enabled=true and configure a hostname — see Ingress and TLS below.
Via port-forward (local testing):
kubectl port-forward -n keycloak svc/keycloak 8080:80
Admin console: http://localhost:8080/admin
Default admin user: admin (set via keycloak.auth.adminUser)
Uninstalling the Chart
helm uninstall keycloak --namespace keycloak
PersistentVolumeClaims are not deleted automatically. Remove them manually if no longer needed:
kubectl delete pvc -l app.kubernetes.io/instance=keycloak -n keycloak
How HA clustering works
This chart deploys Keycloak as a Kubernetes StatefulSet (not a Deployment) because stable pod DNS names are required for Infinispan session-cache discovery.
Clustering sequence:
- The headless Service (
<release>-keycloak-headless) provides stable DNS entries:keycloak-0.<release>-keycloak-headless.<namespace>.svc.cluster.local. - Keycloak uses the
kubernetesJGroups stack (cache.stack: kubernetes) to perform DNS discovery across all headless service endpoints. - Infinispan replicates session data to
cache.ownerspod replicas (default: 2). A single-pod failure loses no sessions. - JGroups uses ports 7800 (gossip/unicast) and 57800 (failure detection) — both allowed in the default NetworkPolicy.
Scaling:
kubectl scale statefulset keycloak --replicas=5 -n keycloak
Update replicaCount in your values file for persistent changes. The default topologySpreadConstraints automatically distributes replicas across nodes and availability zones.
Configuration
Image
| Key | Default | Description |
|---|---|---|
image.registry | quay.io | Image registry |
image.repository | keycloak/keycloak | Image repository |
image.tag | 26.6.2 | Image tag |
image.digest | "" | Digest takes precedence over tag — recommended for production |
image.pullPolicy | IfNotPresent | Image pull policy |
global.imagePullSecrets | [] | Image pull secrets applied to all pods |
Pin to digest in production:
image:
tag: "26.6.2"
digest: "sha256:<digest>"
Replicas and HA
| Key | Default | Description |
|---|---|---|
replicaCount | 3 | Pod replicas — minimum 3 for HA |
autoscaling.enabled | false | Enable HPA |
autoscaling.minReplicas | 3 | HPA minimum replicas |
autoscaling.maxReplicas | 10 | HPA maximum replicas |
autoscaling.targetCPUUtilizationPercentage | 70 | HPA CPU target |
pdb.enabled | true | Enable PodDisruptionBudget |
pdb.minAvailable | 1 | Minimum available pods during disruptions |
terminationGracePeriodSeconds | 60 | Grace period — allows Infinispan to rebalance before exit |
Admin credentials
| Key | Default | Description |
|---|---|---|
keycloak.auth.adminUser | admin | Admin username |
keycloak.auth.adminPassword | "" | Admin password — dev only, use existingSecret in production |
keycloak.auth.existingSecret | "" | Name of existing Secret containing admin password |
keycloak.auth.existingSecretKey | admin-password | Key inside the existing Secret |
Create the secret manually:
kubectl create secret generic keycloak-admin \
--from-literal=admin-password=<password> \
-n keycloak
keycloak:
auth:
existingSecret: keycloak-admin
existingSecretKey: admin-password
Database
Keycloak requires PostgreSQL. The bundled.enabled option is for development only.
| Key | Default | Description |
|---|---|---|
database.vendor | postgres | DB vendor: postgres, mysql, mariadb |
database.host | "" | PostgreSQL hostname (required when not using bundled) |
database.port | 5432 | PostgreSQL port |
database.name | keycloak | Database name |
database.username | keycloak | Database username |
database.password | "" | Database password — dev only, use existingSecret in production |
database.existingSecret | "" | Name of existing Secret containing DB password |
database.existingSecretKey | db-password | Key inside the existing Secret |
Production pattern:
kubectl create secret generic keycloak-db \
--from-literal=db-password=<password> \
-n keycloak
database:
host: postgres.example.com
username: keycloak
existingSecret: keycloak-db
existingSecretKey: db-password
Database checker
The dbchecker init container polls PostgreSQL before Keycloak starts, preventing false startup failures during cold cluster restarts where the database pod may not yet be ready.
| Key | Default | Description |
|---|---|---|
dbchecker.enabled | false | Enable the DB checker init container |
dbchecker.image.repository | busybox | Init container image |
dbchecker.image.tag | 1.37 | Init container image tag |
skipInitContainers | false | Skip all init containers — relies on Keycloak's own retry loop. Requires securityContext.readOnlyRootFilesystem: false — the init-quarkus container that populates /opt/keycloak/lib/quarkus is also skipped, so Keycloak will fail to start if the filesystem is read-only. |
Recommended for production:
dbchecker:
enabled: true
Proxy and hostname
| Key | Default | Description |
|---|---|---|
proxy.mode | xforwarded | KC_PROXY_HEADERS: xforwarded (nginx/ALB) or forwarded (RFC 7239) |
proxy.hostnameStrict | "false" | KC_HOSTNAME_STRICT: reject requests for unknown hostnames |
proxy.http.enabled | true | Enable HTTP listener — set false for end-to-end TLS |
Ingress and TLS
| Key | Default | Description |
|---|---|---|
ingress.enabled | false | Enable Ingress |
ingress.className | "" | IngressClass name (e.g. nginx) |
ingress.annotations | {} | Ingress annotations |
ingress.hosts | see values | Ingress host rules |
ingress.tls | [] | TLS configuration |
With cert-manager:
ingress:
enabled: true
className: nginx
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
nginx.ingress.kubernetes.io/proxy-buffer-size: "128k"
hosts:
- host: keycloak.example.com
paths:
- path: /
pathType: Prefix
tls:
- secretName: keycloak-tls
hosts:
- keycloak.example.com
With an existing TLS secret:
ingress:
enabled: true
tls:
- secretName: my-existing-tls-secret
hosts:
- keycloak.example.com
Cache / clustering
Keycloak uses Infinispan for distributed session storage. JGroups DNS discovery requires stable pod names — the chart uses a StatefulSet for this reason.
| Key | Default | Description |
|---|---|---|
cache.stack | kubernetes | Discovery stack: kubernetes (DNS), tcp, udp |
cache.owners | 2 | Number of replicas holding a copy of each session entry |
replicaCount: 3
cache:
stack: kubernetes
owners: 2
Service
| Key | Default | Description |
|---|---|---|
service.type | ClusterIP | Service type |
service.port | 80 | HTTP service port |
service.httpsPort | 443 | HTTPS service port |
service.annotations | {} | Annotations (e.g. AWS NLB) |
The Service exposes three named ports: http (80), https (443), and management (9000). The management port is required for Prometheus ServiceMonitor scraping and helm test.
Persistence
Used for custom themes and provider JARs. Disabled by default — use extraVolumes for read-only providers.
| Key | Default | Description |
|---|---|---|
persistence.enabled | false | Enable PVC for themes/providers |
persistence.size | 1Gi | PVC size |
persistence.storageClass | "" | Storage class (cluster default if empty) |
global.storageClass | "" | Global storage class override |
Custom themes and providers
Mount a theme or provider JAR via an init container:
initContainers:
- name: copy-theme
image: my-registry/my-theme:1.0.0
command: ["cp", "-r", "/theme", "/themes"]
volumeMounts:
- name: themes
mountPath: /themes
extraVolumes:
- name: themes
emptyDir: {}
extraVolumeMounts:
- name: themes
mountPath: /opt/keycloak/themes/my-theme
Resources
| Key | Default | Description |
|---|---|---|
resources.requests.cpu | 500m | CPU request |
resources.requests.memory | 1Gi | Memory request |
resources.limits.memory | 2Gi | Memory limit — no CPU limit (prevents token validation throttling) |
JVM optio
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.3.5 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