feat(keycloak): shared session cache for multi-replica (swarm)

Swarm: KC_CACHE=ispn + KC_CACHE_STACK=jdbc-ping so replicas share an Infinispan session/realm cache via JDBC_PING2 over the existing Postgres (no multicast, built-in + auto-table in 26.6.3). Compose: KC_CACHE=local (single node). Realm-import scale-back uses KEYCLOAK_REPLICAS/_WANT constants; DB network attached only when the DB is shared (KEYCLOAK_DB_NETWORK_ARG). Does NOT by itself fix the admin-console static-chunk 404 (that needs a shared gzip cache / sticky routing).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
kevinveenbirkenbachandClaude Opus 4.8 committed 2026-07-01 01:04:08 +02:00
1 parent b94ffdaded
commit 2f84fd4058
3 files changed
+14 -5

No files matched your search

@@ -30,7 +30,7 @@
--constraint node.role==manager \
--env-file {{ lookup('container', application_id, 'files.env') | quote }} \
--network {{ application_id | get_entity_name | quote }} \
--network {{ lookup('database', application_id, 'id') | get_entity_name | quote }} \
{{ KEYCLOAK_DB_NETWORK_ARG }} \
--mount type=bind,source={{ KEYCLOAK_REALM_IMPORT_DIR_HOST | quote }},target={{ KEYCLOAK_REALM_IMPORT_DIR_DOCKER | quote }},readonly \
--entrypoint /opt/keycloak/bin/kc.sh \
{{ KEYCLOAK_IMAGE }}:{{ KEYCLOAK_VERSION }} \
@@ -61,8 +61,7 @@
- name: "📏 Keycloak realm-import | Scale keycloak back to nominal replicas"
ansible.builtin.shell: >
container service update --detach --replicas
{{ groups[application_id] | default([inventory_hostname]) | length }}
container service update --detach --replicas {{ KEYCLOAK_REPLICAS }}
{{ lookup('container_service', application_id, entity_name) | quote }}
changed_when: true
delegate_to: "{{ STACK_HOST }}"
@@ -71,7 +70,7 @@
ansible.builtin.shell: |
set -euo pipefail
SVC={{ lookup('container_service', application_id, entity_name) | quote }}
WANT={{ groups[application_id] | default([inventory_hostname]) | length }}/{{ groups[application_id] | default([inventory_hostname]) | length }}
WANT={{ KEYCLOAK_REPLICAS_WANT }}
got="$(container service ls --filter name="$SVC" --format '{{ "{{.Replicas}}" }}' | head -1)"
test "$got" = "$WANT"
register: kc_replicas_converged
@@ -85,7 +84,7 @@
ansible.builtin.script: "{{ role_path }}/files/wait_replicas_stable.sh"
environment:
SVC: "{{ lookup('container_service', application_id, entity_name) }}"
WANT: "{{ groups[application_id] | default([inventory_hostname]) | length }}/{{ groups[application_id] | default([inventory_hostname]) | length }}"
WANT: "{{ KEYCLOAK_REPLICAS_WANT }}"
register: kc_replicas_stable
changed_when: false
retries: 10
+7
View File
@@ -14,6 +14,13 @@ KC_HOSTNAME_STRICT_HTTPS=false
# Proxy
KC_PROXY_HEADERS=xforwarded
{% if DEPLOYMENT_MODE == 'swarm' %}
KC_CACHE=ispn
KC_CACHE_STACK=jdbc-ping
{% else %}
KC_CACHE=local
{% endif %}
# Health Checks
# @see https://quarkus.io/guides/smallrye-health
KC_HEALTH_ENABLED={{ KEYCLOAK_HEALTH_ENABLED | lower }}
+3
View File
@@ -84,6 +84,9 @@ KEYCLOAK_CID_RESOLVE_CMD: >-
--format '{{ "{{.ID}}" }}' | head -1
KEYCLOAK_IMAGE: "{{ lookup('config', application_id, 'services.keycloak.image') }}"
KEYCLOAK_VERSION: "{{ lookup('config', application_id, 'services.keycloak.version') }}"
KEYCLOAK_REPLICAS: "{{ groups[application_id] | length }}"
KEYCLOAK_REPLICAS_WANT: "{{ KEYCLOAK_REPLICAS }}/{{ KEYCLOAK_REPLICAS }}"
KEYCLOAK_DB_NETWORK_ARG: "{% if lookup('database', application_id, 'shared') | bool %}--network {{ lookup('database', application_id, 'network') | quote }}{% endif %}"
KEYCLOAK_REDIRECT_FEATURES: ["services.sso.enabled", "services.sso.enabled"]
KEYCLOAK_FRONTCHANNEL_LOGOUT_URL: "{{ lookup('tls', 'web-svc-logout', 'url.base') }}"