Skip to Content
IAM
Installation
IAM: Keycloak Database Configuration

IAM: Keycloak Database Configuration

This document outlines the supported ways to configure the database for Keycloak in the IAM Helm chart: Cloud Native PostgreSQL (CNPG) (default) or an external PostgreSQL database.

Warning

Bundled Bitnami PostgreSQL removed

The previous keycloak.postgresql.enabled option (Bitnami PostgreSQL subchart) is no longer available. Use CNPG or point keycloak.externalDatabase at an existing PostgreSQL instance.

Cloud Native PostgreSQL (CNPG) Operator

This chart supports using the Cloud Native PostgreSQL (CNPG) operator  to manage the PostgreSQL cluster for Keycloak. CNPG is the default database option shipped with the chart.

Configuration

The CNPG operator must be installed in the Kubernetes cluster. In air-gapped clusters, the operator and PostgreSQL images must be mirrored first; see IAM: Air-gapped Environment.

Enable CNPG and configure the cluster

keycloak: cnpg: enabled: true cluster: name: "keycloak-cnpg-cluster" instances: 3 storage: size: 10Gi database: keycloak username: keycloak secretName: "keycloak-cnpg-secret" backups: enabled: true retentionPolicy: "14d" schedule: "0 3 * * *" barmanObjectStore: destinationPath: "s3://your-bucket-name/keycloak-backups" s3Credentials: secretName: "s3-backup-credentials" accessKeyId: key: "accessKeyId" secretAccessKey: key: "secretAccessKey"

Configure Keycloak to use the CNPG cluster as an external database

The CNPG operator creates a service for the PostgreSQL cluster. Keycloak connects to it via externalDatabase. The service name is typically <cluster-name>-rw.

keycloak: externalDatabase: host: "{{ .Release.Name }}-keycloak-cnpg-rw" # Corresponds to cnpg.cluster.name port: 5432 user: "{{ .Values.keycloak.cnpg.cluster.username }}" database: "{{ .Values.keycloak.cnpg.cluster.database }}" existingSecret: "{{ .Values.keycloak.cnpg.cluster.secretName }}" existingSecretPasswordKey: "password"

This configuration creates a Cluster resource for the CNPG operator, which then provisions and manages the PostgreSQL cluster. Keycloak is configured to connect to that cluster.

Backup and Restore

When using the CNPG operator, backups can be configured to an S3-compatible object store under keycloak.cnpg.cluster.backups. Provide an S3 bucket destination path and a secret containing S3 credentials.

External PostgreSQL Database Configuration

To connect to an existing PostgreSQL database outside the chart, disable CNPG and configure keycloak.externalDatabase.

Disable CNPG

keycloak: cnpg: enabled: false

Provide the connection details for the external database

keycloak: externalDatabase: host: "your-external-postgres-host" port: 5432 user: "your-database-user" database: "your-database-name" existingSecret: "your-postgres-credentials-secret" existingSecretPasswordKey: "password" # The key in the secret that holds the password

A Kubernetes secret containing the database password must exist. existingSecret is the name of that secret.