Need help on cache stack ec2

689 views
Skip to first unread message

Arulaln A R

unread,
Jul 25, 2022, 12:07:48 PM7/25/22
to keyclo...@googlegroups.com
Hi Team,

We are trying to run Keycloak version 18, based on the EKS cluster. We are trying to build a HA cluster. I have gone through the configuration, where the "KC_CACHE_STACK" value should be defined as "ec2" since our EKS cluster worker nodes run on EC2 instances.

Can see, need to update the pom.xml details and also need to include the aws region, bucket details. 

But not sure what are the configurations i have to carry out under /opt/keycloak/conf/cache-ispn.xml.

If any of the members have carried out this configuration, do let me know. 

Really appreciate if you have any working documents handy which describes all the steps to include "ec2" cache stack

--
Regards,
Arulaln A R

Johannes Reppin

unread,
Jul 26, 2022, 2:15:05 AM7/26/22
to Keycloak User
Hi,
From the documentaion: 

>Note that none of these stacks are Kubernetes / OpenShift stacks, so no need exists to enable the "google" stack if you want to run Keycloak on top of the Google Kubernetes engine. In that case, use the kubernetes stack. 

So go with `kubernetes` instead of `ec2`.
cheers

Arulaln A R

unread,
Jul 26, 2022, 3:13:04 AM7/26/22
to Johannes Reppin, Keycloak User
HI Johannes,

Below is the complete sentence of the document. For AWS EC2 instances, we can't use the kubernetes stack. Only ec2 should be used.

The following table shows transport stacks that are supported by Keycloak, but need some extra steps to work. Note that none of these stacks are Kubernetes / OpenShift stacks, so no need exists to enable the "google" stack if you want to run Keycloak on top of the Google Kubernetes engine. In that case, use the kubernetes stack. Instead, when you have a distributed cache setup running on AWS EC2 instances, you would need to set the stack to ec2, because ec2 does not support a default discovery mechanism such as UDP.

Stack name

Transport protocol

Discovery

ec2

TCP

NATIVE_S3_PING

google

TCP

GOOGLE_PING2

azure

TCP

AZURE_PING

Cloud vendor specific stacks have additional dependencies for Keycloak. For more information and links to repositories with these dependencies, see the Infinispan documentation.


--
You received this message because you are subscribed to the Google Groups "Keycloak User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keycloak-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/keycloak-user/1cdb372d-2486-408b-b080-54e0a9984ca9n%40googlegroups.com.

Bruno Ribeiro

unread,
Jul 28, 2022, 5:26:06 AM7/28/22
to Keycloak User
Hey Arulaln,

Even if you're running on an EC2 environment, you can use other ways for discovery, such as JDBC or DNS. But the default config for ec2 is NATIVE_S3_PING. I'm assuming you're going with NATIVE_S3_PING as you talked about AWS configurations, so this might help you: https://github.com/jgroups-extras/jgroups-aws

And the default ec2 configuration provided by Infinispan: https://github.com/infinispan/infinispan/blob/main/core/src/main/resources/default-configs/default-jgroups-ec2.xml

So maybe setting the JAVA_OPTS_APPEND environment variable to something like the below works (assuming you're using the quarkus distribution and AWS credentials are correctly set):

JAVA_OPTS_APPEND=-Djgroups.s3.region_name={put-the-region-here} -Djgroups.s3.bucket_name={put-your-bucket-name-here}

Best,

Arulaln A R

unread,
Jul 28, 2022, 10:37:16 AM7/28/22
to Bruno Ribeiro, Keycloak User
Thanks Bruno, when I run on EKS cluster I can still use the kubernetes stack?
Only when I run keycloak as the local to EC2 instances should I go for ec2 stack?

please confirm this point

Bruno César

unread,
Jul 28, 2022, 10:53:18 AM7/28/22
to Arulaln A R, Keycloak User
Hi Arulaln,

AFAIK, you can set the cache stack config to Kubernetes when running on EKS. I never run it on EKS, but on GKE, OpenShift and local cluster I only need something like the below for JAVA_OPTS_APPEND.
-Djgroups.dns.query={{ your service name here }}.{{ .Release.Namespace }}.svc.cluster.local
KC_CACHE_STACK is set to "kubernetes", of course.
Best,

Bruno Ribeiro
http://brunocesar.com

Arulaln A R

unread,
Jul 28, 2022, 11:02:49 AM7/28/22
to Bruno César, Keycloak User
Hi Bruno,

Thanks, yes. cache stack should be supplied during the build stage itself. JAVA_OPTS_APPEND environment variable let me give it during starting keycloak as a pod

Arulaln A R

unread,
Jul 29, 2022, 3:57:32 AM7/29/22
to Bruno César, Keycloak User
HI Bruno,

I have set up according to the comments below, but don't see any cluster nodes formed. I think, according to the article the service which keycloak is exposed to should be headless service (clusterip is none), in our case it is not. Maybe that might be the reason? I don't see any error. I ran it with two instances both have started up and running without any issues. Only think it wasn't recognised as a cluster.

Example Kubernetes Yaml env details :
- name: JAVA_OPTS_APPEND
  value: "-Djgroups.dns.query=servicename.namespace.svc.cluster.local"

During build stage itself i have set the environment varible under Dockerfile "ENV KC_CACHE_STACK=kubernetes"

You mentioned in your earlier email that you have setup in GKE, kubernetes. What type of service your keycloak is exposed? is it LB/clusterip/NodePort

Bruno César

unread,
Jul 29, 2022, 5:42:48 AM7/29/22
to Arulaln A R, Keycloak User
Hi Arulaln,

For the discovery service, I'm using ClusterIP and setting clusterIP to None, basically, like the below:
apiVersion: v1
kind: Service
metadata:
name: keycloak-discovery
labels:
{{ include "labels" . | nindent 4 }}
spec:
type: ClusterIP
ports:
- protocol: TCP
port: 8080
targetPort: 8080
clusterIP: None
sessionAffinity: None
selector:
app: {{ template "selector.name" . }}
release: {{ .Release.Name }}
It is pretty much like the one in the Keycloak Operator.

Best,

Arulaln A R

unread,
Jul 29, 2022, 8:54:12 AM7/29/22
to Bruno César, Keycloak User
Thanks Bruno, we also followed a similar setup. Where we have two services (headless and normal service) pointing to the same keycloak applications. And used the headless service for dns ping (kubernetes stack). Works smoothly.
Reply all
Reply to author
Forward
0 new messages