keycloak

by arieotech

Helm chartv0.3.5App 26.6.2Apache-2.0Verified publisher

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:

GapImpact
No PSA restricted-mode supportreadOnlyRootFilesystem: true crashes Keycloak at startup — Quarkus writes to /opt/keycloak/lib/quarkus/ on every cold start
KC_HEALTH_ENABLED not setAll probes fail with "connection refused" on every fresh install
No NetworkPolicyPod networking is open by default; ingress controller and inter-pod clustering are unrestricted
No JSON Schema validationInvalid values are silently ignored instead of rejected at install time
Management port not on main ServicePrometheus ServiceMonitors can't scrape /metrics; helm test pods can't reach /health/*
JGroups ports not updatedClustering fails silently on Keycloak 25+ (ports changed from 7600 to 7800)
No SOC2/DPDP compliance defaultsEach team re-implements audit logging and PII masking from scratch
No E2E validationCharts 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.enabled is 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:

  1. The headless Service (<release>-keycloak-headless) provides stable DNS entries: keycloak-0.<release>-keycloak-headless.<namespace>.svc.cluster.local.
  2. Keycloak uses the kubernetes JGroups stack (cache.stack: kubernetes) to perform DNS discovery across all headless service endpoints.
  3. Infinispan replicates session data to cache.owners pod replicas (default: 2). A single-pod failure loses no sessions.
  4. 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

KeyDefaultDescription
image.registryquay.ioImage registry
image.repositorykeycloak/keycloakImage repository
image.tag26.6.2Image tag
image.digest""Digest takes precedence over tag — recommended for production
image.pullPolicyIfNotPresentImage 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

KeyDefaultDescription
replicaCount3Pod replicas — minimum 3 for HA
autoscaling.enabledfalseEnable HPA
autoscaling.minReplicas3HPA minimum replicas
autoscaling.maxReplicas10HPA maximum replicas
autoscaling.targetCPUUtilizationPercentage70HPA CPU target
pdb.enabledtrueEnable PodDisruptionBudget
pdb.minAvailable1Minimum available pods during disruptions
terminationGracePeriodSeconds60Grace period — allows Infinispan to rebalance before exit

Admin credentials

KeyDefaultDescription
keycloak.auth.adminUseradminAdmin username
keycloak.auth.adminPassword""Admin password — dev only, use existingSecret in production
keycloak.auth.existingSecret""Name of existing Secret containing admin password
keycloak.auth.existingSecretKeyadmin-passwordKey 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.

KeyDefaultDescription
database.vendorpostgresDB vendor: postgres, mysql, mariadb
database.host""PostgreSQL hostname (required when not using bundled)
database.port5432PostgreSQL port
database.namekeycloakDatabase name
database.usernamekeycloakDatabase username
database.password""Database password — dev only, use existingSecret in production
database.existingSecret""Name of existing Secret containing DB password
database.existingSecretKeydb-passwordKey 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.

KeyDefaultDescription
dbchecker.enabledfalseEnable the DB checker init container
dbchecker.image.repositorybusyboxInit container image
dbchecker.image.tag1.37Init container image tag
skipInitContainersfalseSkip 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

KeyDefaultDescription
proxy.modexforwardedKC_PROXY_HEADERS: xforwarded (nginx/ALB) or forwarded (RFC 7239)
proxy.hostnameStrict"false"KC_HOSTNAME_STRICT: reject requests for unknown hostnames
proxy.http.enabledtrueEnable HTTP listener — set false for end-to-end TLS

Ingress and TLS

KeyDefaultDescription
ingress.enabledfalseEnable Ingress
ingress.className""IngressClass name (e.g. nginx)
ingress.annotations{}Ingress annotations
ingress.hostssee valuesIngress 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.

KeyDefaultDescription
cache.stackkubernetesDiscovery stack: kubernetes (DNS), tcp, udp
cache.owners2Number of replicas holding a copy of each session entry
replicaCount: 3
cache:
  stack: kubernetes
  owners: 2

Service

KeyDefaultDescription
service.typeClusterIPService type
service.port80HTTP service port
service.httpsPort443HTTPS 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.

KeyDefaultDescription
persistence.enabledfalseEnable PVC for themes/providers
persistence.size1GiPVC 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

KeyDefaultDescription
resources.requests.cpu500mCPU request
resources.requests.memory1GiMemory request
resources.limits.memory2GiMemory 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.

  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.3.5 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