keycloak-operator

by Hostzero

Helm chartv0.14.0App 0.14.0

A Kubernetes operator for managing Keycloak resources

About this chart

Keycloak Operator Helm Chart

A Helm chart for deploying the Keycloak Operator to Kubernetes.

Prerequisites

  • Kubernetes 1.25+
  • Helm 3.0+

Installation

From OCI Registry (Recommended)

helm install keycloak-operator oci://ghcr.io/hostzero-gmbh/charts/keycloak-operator \
  --namespace keycloak-operator \
  --create-namespace

From local chart

helm install keycloak-operator ./charts/keycloak-operator \
  --namespace keycloak-operator \
  --create-namespace

Install with custom values

helm install keycloak-operator ./charts/keycloak-operator \
  --namespace keycloak-operator \
  --create-namespace \
  --values my-values.yaml

Configuration

See values.yaml for the full list of configurable parameters.

Common Configuration Options

ParameterDescriptionDefault
replicaCountNumber of replicas1
image.repositoryContainer image repositoryghcr.io/hostzero-gmbh/keycloak-operator
image.tagContainer image tagChart appVersion
image.pullPolicyImage pull policyIfNotPresent
resources.limits.cpuCPU limit500m
resources.limits.memoryMemory limit256Mi
resources.requests.cpuCPU request100m
resources.requests.memoryMemory request128Mi
leaderElection.enabledEnable leader electiontrue
metrics.enabledEnable metrics endpointtrue
metrics.serviceMonitor.enabledCreate ServiceMonitorfalse
logging.levelLog level (debug, info, error)info
logging.formatLog format (json, console)json
otel.enabledEnable OTLP traces and logsfalse
crds.installInstall CRDstrue
crds.keepKeep CRDs on uninstalltrue

Usage

Create a Keycloak Instance Connection

First, create a secret with your Keycloak admin credentials:

kubectl create secret generic keycloak-credentials \
  --from-literal=username=admin \
  --from-literal=password=your-password

Then create a KeycloakInstance resource:

apiVersion: keycloak.hostzero.com/v1beta1
kind: KeycloakInstance
metadata:
  name: my-keycloak
spec:
  baseUrl: https://keycloak.example.com
  auth:
    passwordGrant:
      secretRef:
        name: keycloak-credentials

Create a Realm

apiVersion: keycloak.hostzero.com/v1beta1
kind: KeycloakRealm
metadata:
  name: my-realm
spec:
  instanceRef:
    name: my-keycloak
  definition:
    realm: my-realm
    enabled: true
    displayName: My Realm

Create a Client

apiVersion: keycloak.hostzero.com/v1beta1
kind: KeycloakClient
metadata:
  name: my-app
spec:
  realmRef:
    name: my-realm
  definition:
    clientId: my-app
    enabled: true
    protocol: openid-connect
    publicClient: false
  clientSecretRef:
    name: my-app-credentials

Uninstallation

helm uninstall keycloak-operator -n keycloak-operator

Note: By default, CRDs are kept when uninstalling. To remove them:

kubectl delete crd keycloakinstances.keycloak.hostzero.com
kubectl delete crd keycloakrealms.keycloak.hostzero.com
kubectl delete crd keycloakclients.keycloak.hostzero.com
kubectl delete crd keycloakusers.keycloak.hostzero.com
kubectl delete crd keycloakclientscopes.keycloak.hostzero.com
kubectl delete crd keycloakgroups.keycloak.hostzero.com
kubectl delete crd keycloakidentityproviders.keycloak.hostzero.com

Development

Lint the chart

helm lint ./charts/keycloak-operator

Template rendering

helm template keycloak-operator ./charts/keycloak-operator

Package the chart

helm package ./charts/keycloak-operator

Deploy keycloak-operator with OpenTenant

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