keycloak-operator
by sergk
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
- Kubernetes 1.32 or later, or OpenShift 4.19 or later;
- Linux machine or Windows Subsystem for Linux instance with Helm 3 installed;
- Cluster admin access to the cluster;
- 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:
-
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 -
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 OperatorNOTE: It is highly recommended to use the latest stable version.
-
Full chart parameters available below.
-
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 -
Check the namespace containing Deployment with your operator in running status.
Helm does not upgrade CRDs. See Upgrade.
Quick Start
-
Create a User in the Keycloak
Masterrealm, and assign acreate-realmrole. -
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" -
Create Custom Resource
kind: Keycloakwith 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 URLWait for the
.statusfield withstatus.connected: true -
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: KeycloakapiVersion: v1.edp.epam.com/v1 kind: KeycloakRealmGroup metadata: name: argocd-admins spec: name: ArgoCDAdmins realmRef: name: keycloakrealm-sample # the name of `kind: KeycloakRealm` kind: KeycloakRealmInspect 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
| Name | Url | |
|---|---|---|
| epmd-edp | [email protected] | https://solutionshub.epam.com/solution/kuberocketci |
| sergk | https://github.com/SergK |
Source Code
Requirements
Kubernetes: >=1.32.0-0
Values
| Key | Type | Default | Description |
|---|---|---|---|
| affinity | object | {} | Affinity for pod assignment |
| allowedDestinationHosts | list | [] | 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. |
| annotations | object | {} | Annotations to be added to the Deployment |
| clusterDomain | string | "cluster.local" | Cluster domain for constructing service DNS names |
| clusterReconciliationEnabled | bool | false | If 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. |
| containerSecurityContext | object | {"allowPrivilegeEscalation":false} | Container Security Context Ref: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/ |
| enableOwnerRef | bool | true | If 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. |
| enableWebhooks | bool | true | If set to true, enables webhook resources (ValidatingWebhookConfiguration, Service, and Certificate). Webhooks require cert-manager to be installed in the cluster. |
| enforceDestinationAllowlist | bool | false | If 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. |
| extraVolumeMounts | list | [] | Additional volumeMounts to be added to the container |
| extraVolumes | list | [] | Additional volumes to be added to the pod |
| image.registry | string | "" | KubeRocketCI keycloak-operator Docker image registry. |
| image.repository | string | "epamedp/keycloak-operator" | KubeRocketCI keycloak-operator Docker image name. The released image can be found on Dockerhub |
| image.tag | string | nil | KubeRocketCI keycloak-operator Docker image tag. The released image can be found on Dockerhub |
| imagePullPolicy | string | "IfNotPresent" | If defined, a imagePullPolicy applied to the deployment |
| imagePullSecrets | list | [] | If defined, imagePullSecrets are applied to deployment |
| name | string | "keycloak-operator" | Application name string |
| nodeSelector | object | {} | Node labels for pod assignment |
| podLabels | object | {} | Labels to be added to the pod |
| replicaCount | int | 1 | Number of operator replicas. |
| resources | object | {"limits":{"memory":"192Mi"},"requests":{"cpu":"50m","memory":"64Mi"}} | Resource limits and requests for the pod |
| securityContext | object | {"runAsNonRoot":true} | Deployment Security Context Ref: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/ |
| serviceAccount | object | {"annotations":{},"create":true,"labels":{},"name":"edp-keycloak-operator"} | ServiceAccount configuration |
| serviceAccount.annotations | object | {} | Annotations to add to the ServiceAccount (e.g. for AWS IAM role association) |
| serviceAccount.create | bool | true | If true, a ServiceAccount will be created |
| serviceAccount.labels | object | {} | Additional labels to add to the ServiceAccount |
| serviceAccount.name | string | "edp-keycloak-operator" | The name of the ServiceAccount to use. Defaults to "edp-keycloak-operator" |
| successReconcileTimeout | string | "" | 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. |
| tolerations | list | [] | 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.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartkeycloak-operator is pinned at v1.37.0-SNAPSHOT.7 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