keycloak-operator

by sergk

Helm chartv1.37.0-SNAPSHOT.7App 1.37.0-SNAPSHOT.7Apache-2.0Verified publisher

A Helm chart for KubeRocketCI Keycloak Operator

About this chart

keycloak-operator

A Helm chart for KubeRocketCI Keycloak Operator

Homepage: https://docs.kuberocketci.io/

Overview

Keycloak Operator is a KubeRocketCI operator responsible for configuring existing Keycloak instances. The operator runs both on OpenShift and Kubernetes.

NOTE: Operator is platform-independent, which is why there is a unified instruction for deployment.

Prerequisites

  1. Kubernetes 1.32 or later, or OpenShift 4.19 or later;
  2. Linux machine or Windows Subsystem for Linux instance with Helm 3 installed;
  3. Cluster admin access to the cluster;
  4. cert-manager installed in the cluster (required for webhook functionality, can be disabled via enableWebhooks: false);

Installation Using Helm Chart

To install the Keycloak Operator, follow the steps below:

  1. To add the Helm EPAMEDP Charts for a local client, run "helm repo add":

    helm repo add epamedp https://epam.github.io/edp-helm-charts/stable
    
  2. Choose the available Helm chart version:

    helm search repo epamedp/keycloak-operator -l
    NAME                           CHART VERSION   APP VERSION     DESCRIPTION
    epamedp/keycloak-operator      1.31.0          1.31.0          A Helm chart for KRCI Keycloak Operator
    

    NOTE: It is highly recommended to use the latest stable version.

  3. Full chart parameters available below.

  4. Install the operator in the namespace with the helm command; find below the installation command example:

    helm install keycloak-operator epamedp/keycloak-operator --version <chart_version> --namespace <edp-project> --set name=keycloak-operator
    
  5. Check the namespace containing Deployment with your operator in running status.

Helm does not upgrade CRDs. See Upgrade.

Quick Start

  1. Create a User in the Keycloak Master realm, and assign a create-realm role.

  2. Insert newly created user credentials into Kubernetes secret:

    apiVersion: v1
    kind: Secret
    metadata:
      name:  keycloak-access
    type: Opaque
    data:
      username: dXNlcg==   # base64-encoded value of "user"
      password: cGFzcw==   # base64-encoded value of "pass"
    
  3. Create Custom Resource kind: Keycloak with Keycloak instance URL and secret created on the previous step:

    apiVersion: v1.edp.epam.com/v1
    kind: Keycloak
    metadata:
      name: keycloak-sample
    spec:
      secret: keycloak-access             # Secret name
      url: https://keycloak.example.com   # Keycloak URL
    

    Wait for the .status field with status.connected: true

  4. Create Keycloak realm and group using Custom Resources:

    apiVersion: v1.edp.epam.com/v1
    kind: KeycloakRealm
    metadata:
      name: keycloakrealm-sample
    spec:
      realmName: realm-sample
      keycloakRef:
        name: keycloak-sample   # the name of `kind: Keycloak`
        kind: Keycloak
    
    apiVersion: v1.edp.epam.com/v1
    kind: KeycloakRealmGroup
    metadata:
      name: argocd-admins
    spec:
      name: ArgoCDAdmins
      realmRef:
        name: keycloakrealm-sample   # the name of `kind: KeycloakRealm`
        kind: KeycloakRealm
    

    Inspect available custom resource and CR templates folder for more examples

Local Development

To develop the operator, first set up a local environment, and refer to the Local Development page.

Development versions are also available from the snapshot helm chart repository page.

Related Articles

Maintainers

NameEmailUrl
epmd-edp[email protected]https://solutionshub.epam.com/solution/kuberocketci
sergkhttps://github.com/SergK

Source Code

Requirements

Kubernetes: >=1.32.0-0

Values

KeyTypeDefaultDescription
affinityobject{}Affinity for pod assignment
allowedDestinationHostslist[]Hostnames the operator and Keycloak may reach with credentials resolved from Secrets. Covers Keycloak spec.url and spec.tlsServerName, realm spec.smtp.connection.host, and the known destination keys (tokenUrl, connectionUrl, ...) inside identity provider, realm component and authentication flow authenticator config. Values in other config keys, including the keys of custom providers, are not checked. The operator resolves $secretName:secretKey references with its own ServiceAccount, so whoever writes a KeycloakRealmIdentityProvider, KeycloakRealmComponent or KeycloakAuthFlow can send any Secret of its namespace to an address that resource names. Grant create and update on these kinds only to principals that may read Secrets in that namespace; when a GitOps tool applies them, its repository committers are the authors. See docs/security.md. Exact, case-insensitive match; no wildcards. Write the hostname only, without scheme, port or path, and prefer fully qualified names. An empty list means no policy: every destination is allowed and nothing is logged or counted. Add at least one host (for example the Keycloak host) to turn on reporting.
annotationsobject{}Annotations to be added to the Deployment
clusterDomainstring"cluster.local"Cluster domain for constructing service DNS names
clusterReconciliationEnabledboolfalseIf clusterReconciliationEnabled is true, the operator reconciles all Keycloak instances in the cluster; otherwise, it only reconciles instances in the same namespace by default, and cluster-scoped resources are ignored.
containerSecurityContextobject{"allowPrivilegeEscalation":false}Container Security Context Ref: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/
enableOwnerRefbooltrueIf set to true, the operator will set the owner reference for all resources that have Keycloak or KeycloakRealm as reference. This is legacy behavior and not recommended for use. In the future, this will be set to false by default.
enableWebhooksbooltrueIf set to true, enables webhook resources (ValidatingWebhookConfiguration, Service, and Certificate). Webhooks require cert-manager to be installed in the cluster.
enforceDestinationAllowlistboolfalseIf true, a destination absent from allowedDestinationHosts fails the reconcile. If false, destinations absent from a non-empty list are logged and counted, so the list can be built from a running cluster before enforcement is turned on. Enabling this with an empty allowedDestinationHosts stops the operator at startup.
extraVolumeMountslist[]Additional volumeMounts to be added to the container
extraVolumeslist[]Additional volumes to be added to the pod
image.registrystring""KubeRocketCI keycloak-operator Docker image registry.
image.repositorystring"epamedp/keycloak-operator"KubeRocketCI keycloak-operator Docker image name. The released image can be found on Dockerhub
image.tagstringnilKubeRocketCI keycloak-operator Docker image tag. The released image can be found on Dockerhub
imagePullPolicystring"IfNotPresent"If defined, a imagePullPolicy applied to the deployment
imagePullSecretslist[]If defined, imagePullSecrets are applied to deployment
namestring"keycloak-operator"Application name string
nodeSelectorobject{}Node labels for pod assignment
podLabelsobject{}Labels to be added to the pod
replicaCountint1Number of operator replicas.
resourcesobject{"limits":{"memory":"192Mi"},"requests":{"cpu":"50m","memory":"64Mi"}}Resource limits and requests for the pod
securityContextobject{"runAsNonRoot":true}Deployment Security Context Ref: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/
serviceAccountobject{"annotations":{},"create":true,"labels":{},"name":"edp-keycloak-operator"}ServiceAccount configuration
serviceAccount.annotationsobject{}Annotations to add to the ServiceAccount (e.g. for AWS IAM role association)
serviceAccount.createbooltrueIf true, a ServiceAccount will be created
serviceAccount.labelsobject{}Additional labels to add to the ServiceAccount
serviceAccount.namestring"edp-keycloak-operator"The name of the ServiceAccount to use. Defaults to "edp-keycloak-operator"
successReconcileTimeoutstring""Interval for periodic reconciliation after a successful reconcile, as a Go duration with a unit (for example "10m"); a bare number is rejected. Applies to KeycloakRealm, KeycloakClient, KeycloakRealmGroup, KeycloakRealmRole and KeycloakRealmRoleBatch. Empty disables periodic reconciliation for these resources: they reconcile only on CR changes, operator restart, or the cache resync (~10h). Keycloak and KeycloakRealmUser have no periodic reconciliation. Other resources use fixed intervals and are not affected.
tolerationslist[]Node tolerations for server scheduling to nodes with taints

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 v1.37.0-SNAPSHOT.7 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