codecentric Helm Charts
repository·master·Indexed 20 days ago
https://github.com/codecentric/helm-chartsA collection of curated Helm charts maintained by codecentric, available via a standard Helm repository and as OCI artifacts in the GitHub Container Registry. This includes charts for Keycloak, with a specific legacy Wildfly-based Keycloak chart and a recommended Keycloak-X chart for current and new installations.
What's inside codecentric-helm-charts
- This repository provides various deployment examples for the KeycloakX Helm chart to support custom configurations. The primary examples include integrating KeycloakX with a PostgreSQL database and using KUBE_PING for cluster connectivity/health checks.
How the `tpl` function works in Keycloak configuration
masterThe chart uses the Helm
tplfunction for several configuration keys. This allows you to pass string values fromvalues.yamlthrough the templating engine, enabling dynamic values (like using{{ .Values.someKey }}or{{ include "keycloak.fullname" . }}) within your configuration.Important: These values must be configured as strings in your
values.yaml, otherwise the installation will fail.Supported keys using
tpl:extraInitContainersextraContainersextraEnvextraEnvFromaffinityextraVolumeMountsextraVolumeslivenessProbereadinessProbestartupProbetopologySpreadConstraints- Custom labels and annotations on various resources.
Configure High Availability and Clustering
masterFor High Availability (HA), set
replicas > 1.Cache Stacks:
- Default (Recommended): Since Keycloak 26.1.0, the default is
jdbc-ping, which uses ajgroups_pingtable in the database. This reduces network complexity and works well across cloud providers. - Legacy Kubernetes Stack: If you require the original
kubernetesstack, setcache.stack: customand add the following environment variables:
extraEnv: | - name: KC_CACHE value: "ispn" - name: KC_CACHE_STACK value: "kubernetes" - name: JAVA_OPTS_APPEND value: >- -Djgroups.dns.query={{ include "keycloak.fullname" . }}-headlessCustom Service Discovery: To use a custom Infinispan configuration file (e.g.,
cache-custom.xml), setcache.stack: customand provide the file via theKC_CACHE_CONFIG_FILEenvironment variable. The file must be available at/opt/keycloak/conf/cache-custom.xmlinside the container.cache: stack: custom- Default (Recommended): Since Keycloak 26.1.0, the default is
Why Keycloak uses a StatefulSet
masterThis chart deploys Keycloak using aStatefulSet. This is required because the headless service governing theStatefulSetis used for DNS discovery viaDNS_PING.Access codecentric charts via OCI registry
masterIn addition to the standard Helm repository, the charts are published to the GitHub Container Registry as OCI artifacts. You can pull and use them directly via OCI-compatible Helm commands.Enable WildFly metrics for Prometheus
masterWildFly can expose metrics on the management port. To enable this, you must set the
KEYCLOAK_STATISTICSenvironment variable toallviaextraEnv.If you are using the
prometheus-operator, enable theserviceMonitorto automatically create aServiceMonitorresource. If you are not using the operator, add Prometheus scrape annotations to theserviceconfiguration.# Enable metrics via environment variable extraEnv: | - name: KEYCLOAK_STATISTICS value: all # Enable ServiceMonitor for prometheus-operator serviceMonitor: enabled: trueInstall the Keycloak Helm Chart
masterYou can install the Keycloak chart using either CLI arguments with
--setor a YAML values file.Using CLI arguments:
helm install keycloak codecentric/keycloak -n keycloak --set replicas=1Using a values file:
helm install keycloak codecentric/keycloak -n keycloak --values values.yaml#!/bin/bash helm install keycloak codecentric/keycloak -n keycloak --set replicas=1Configure Keycloak context path
masterTo set a specific context path for Keycloak, use the
--set-stringflag during Helm installation to ensure the value is treated as a string rather than a boolean or number.--set-string contextPath=mycontextAccess the Keycloak Admin Console
masterAfter deploying Keycloak, you can access the Admin Console by forwarding the HTTP service port to your local machine.
- Run the port-forward command:
kubectl port-forward service/keycloak-keycloakx-http 8080:80 - Open your browser to:
http://localhost:8080/auth - Use the following default credentials:
- Username:
admin - Password:
secret
- Username:
kubectl port-forward service/keycloak-keycloakx-http 8080:80- Run the port-forward command:
Restrict access to Keycloak Metrics SPI endpoint via Ingress-Nginx
masterSince the Keycloak Metrics SPI endpoint is exposed on the public HTTP port, you may want to restrict access using your ingress controller. For
ingress-nginx, you can use aserver-snippetannotation to return a403 Forbiddenfor the metrics path.annotations: nginx.ingress.kubernetes.io/server-snippet: | location ~* /auth/realms/[^/]+/metrics { return 403; }Set up Keycloak.X with PostgreSQL using CloudNative-PG
masterThis guide demonstrates how to deploy Keycloak.X configured to use a PostgreSQL database managed by the CloudNative-PG operator. The process involves adding the necessary Helm repositories, deploying the database cluster via Kubernetes manifests, and then installing Keycloak using the
codecentric/keycloakxchart with custom values.# 1. Add repositories helm repo add cnpg https://cloudnative-pg.github.io/charts helm repo add codecentric https://codecentric.github.io/helm-charts helm repo update # 2. Deploy PostgreSQL database kubectl apply -f keycloak-cluster.yaml kubectl wait -for=condition=Ready cluster/keycloak-database --timeout=300s # 3. Deploy Keycloak helm install keycloak codecentric/keycloakx --values ./keycloak-server-values.yamlDeploy Keycloak.X with KUBE_PING
masterTo deploy KeycloakX using KUBE_PING (often used for cluster-aware connectivity or specific health check requirements), refer to the configuration guide in thepostgresql-kubepingexample directory.