update HA for keycloak

This commit is contained in:
2025-03-30 17:55:43 +02:00
parent 476c174981
commit f4b3d0a50e
2 changed files with 67 additions and 7 deletions

View File

@@ -4,6 +4,7 @@ metadata:
name: keycloak name: keycloak
annotations: annotations:
cert-manager.io/cluster-issuer: "letsencrypt-prod" cert-manager.io/cluster-issuer: "letsencrypt-prod"
nginx.ingress.kubernetes.io/backend-protocol: "HTTP"
nginx.ingress.kubernetes.io/force-ssl-redirect: "true" nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
spec: spec:
ingressClassName: nginx ingressClassName: nginx

View File

@@ -1,18 +1,33 @@
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
metadata:
name: keycloak-headless
labels:
app: keycloak
spec:
clusterIP: None # Headless service for DNS discovery (returns pod IPs)
selector:
app: keycloak
ports:
- name: jgroups
port: 7600
targetPort: 7600
protocol: TCP
---
apiVersion: v1
kind: Service
metadata: metadata:
name: keycloak name: keycloak
namespace: keycloak
labels: labels:
app: keycloak app: keycloak
spec: spec:
type: ClusterIP # Internal service for Keycloak (ingress will use this)
selector:
app: keycloak
ports: ports:
- name: http - name: http
port: 8080 port: 8080
targetPort: 8080 targetPort: 8080
selector:
app: keycloak
type: ClusterIP
--- ---
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
@@ -22,7 +37,7 @@ metadata:
labels: labels:
app: keycloak app: keycloak
spec: spec:
replicas: 1 replicas: 3
selector: selector:
matchLabels: matchLabels:
app: keycloak app: keycloak
@@ -34,7 +49,9 @@ spec:
containers: containers:
- name: keycloak - name: keycloak
image: quay.io/keycloak/keycloak:26.1.4 image: quay.io/keycloak/keycloak:26.1.4
args: ["start"] args:
- "start"
- "--cache=ispn" # Enable distributed Infinispan cache (HA mode) [oai_citation_attribution:0‡keycloak.org](https://www.keycloak.org/server/caching#:~:text=When%20you%20start%20Keycloak%20in,in%20your%20network%20are%20discovered)
env: env:
- name: KEYCLOAK_ADMIN - name: KEYCLOAK_ADMIN
value: "admin" value: "admin"
@@ -62,10 +79,52 @@ spec:
secretKeyRef: secretKeyRef:
name: keycloak-db-secret name: keycloak-db-secret
key: password key: password
# --- Clustering and caching settings ---
- name: KC_CACHE_STACK
value: "kubernetes"
- name: jgroups.dns.query
value: "keycloak-headless" # DNS name for JGroups discovery (headless service) [oai_citation_attribution:2‡keycloak.org](https://www.keycloak.org/server/caching#:~:text=DNS%20resolution%20using%20the%20JGroups,to%20the%20headless%20service%20FQDN)
- name: CACHE_OWNERS_COUNT
value: "2"
- name: CACHE_OWNERS_AUTH_SESSIONS_COUNT
value: "2"
# Enable proxy address forwarding since Keycloak is behind an NGINX proxy
- name: PROXY_ADDRESS_FORWARDING
value: "true" # Trust X-Forwarded-* headers [oai_citation_attribution:3‡github.com](https://github.com/codecentric/helm-charts/issues/325#:~:text=extraEnv%3A%20%7C%20,name%3A%20CACHE_OWNERS_AUTH_SESSIONS_COUNT)
- name: KC_PROXY
value: "edge" # Keycloak is behind an edge (TLS termination) proxy
- name: KC_HOSTNAME_STRICT
value: "false" # Disable strict host check (allow internal/external host differences)
# (Optional) Enable health and metrics endpoints for monitoring:
- name: KC_HEALTH_ENABLED
value: "true"
- name: KC_METRICS_ENABLED
value: "true"
ports: ports:
- name: http - name: http
containerPort: 8080 containerPort: 8080
- name: jgroups
containerPort: 7600 # JGroups cluster communication port [oai_citation_attribution:4‡github.com](https://github.com/codecentric/helm-charts/issues/325#:~:text=authSessionTabId%3Dl06agEOwVB4)
protocol: TCP
livenessProbe:
httpGet:
path: /health/live
port: 8080
initialDelaySeconds: 60
periodSeconds: 30
readinessProbe: readinessProbe:
httpGet: httpGet:
path: /health/ready path: /health/ready
port: 9000 port: 8080
initialDelaySeconds: 30
periodSeconds: 15
affinity:
# Spread pods across different nodes for higher availability
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
topologyKey: "kubernetes.io/hostname"
labelSelector:
matchLabels:
app: keycloak