How to configure Keycloak standalone cluster on Cloud Foundry?
I tried to use docker image jboss/keycloak:4.5.0.Final
with internal routing:
I finally found the answer to my own question.
Go to this keycloak4cf repo if you are looking for a quick solution.
Main problems that I had to face:
Use the jboss/keycloak:5.0.0
or newer/latest
There is hardcoded .svc.cluster.local
DNS query suffix removed with JGRP-2295.
This fix was released in JGroups 4.0.15.Final
, that is used in Infinispan Core 9.4.0.Final.
, released with Keycloak 5.0.0
(included inifnispan-core 9.4.3.Final
).
Clustering have to be done with TCP instead of multicast UDP (there is no multicast on Cloud Foundry - thank you @DanielMikusa for the tip).
To change this config use dns.DNS_PING.cli
:
embed-server --server-config=standalone-ha.xml --std-out=echo
batch
/subsystem=jgroups:write-attribute(name=default-stack,value=tcp)
/subsystem=jgroups/channel=ee:write-attribute(name=stack,value=tcp)
/subsystem=jgroups/stack=udp/protocol=PING:remove()
/subsystem=jgroups/stack=udp/protocol=$keycloak_jgroups_discovery_protocol:add(add-index=0, properties=$keycloak_jgroups_discovery_protocol_properties)
/subsystem=jgroups/stack=tcp/protocol=MPING:remove()
/subsystem=jgroups/stack=tcp/protocol=$keycloak_jgroups_discovery_protocol:add(add-index=0, properties=$keycloak_jgroups_discovery_protocol_properties)
run-batch
stop-embedded-server
Add network policy to allow connections between cluster nodes:
cf add-network-policy keycloak-cluster-poc --destination-app keycloak-cluster-poc --protocol tcp --port 7600