fix(keycloak): use management port health endpoints for probes#2162
fix(keycloak): use management port health endpoints for probes#2162kvaps merged 2 commits intocozystack:mainfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical issue causing Keycloak instances to crashloop due to misconfigured liveness and readiness probes. By enabling specific health endpoints and directing Kubernetes probes to the correct management port and paths, the stability and reliability of Keycloak deployments are significantly improved, preventing unnecessary restarts. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Keycloak 26.x exposes dedicated health endpoints on the management port (9000) via /health/live and /health/ready. The previous probes used GET / on port 8080 which redirects to the configured KC_HOSTNAME (HTTPS), causing kubelet to fail the probe with "Probe terminated redirects" and eventually kill the pod in a crashloop. Changes: - Add KC_HEALTH_ENABLED=true to activate health endpoints - Expose management port 9000 in container ports - Switch liveness probe to /health/live on port 9000 - Switch readiness probe to /health/ready on port 9000 - Increase failure thresholds for more tolerance during startup Co-Authored-By: Claude Opus 4.6 <[email protected]> Signed-off-by: mattia-eleuteri <[email protected]>
c9a52fb to
0873691
Compare
There was a problem hiding this comment.
Code Review
This pull request correctly fixes a crash loop in Keycloak by reconfiguring the health probes to use the management port and its dedicated health endpoints. The changes are logical and directly address the described problem. I have added one suggestion to further enhance the probe configuration by introducing a startupProbe. This is a Kubernetes best practice for applications with slow startup times like Keycloak, and it will make the deployment more robust by preventing premature restarts during initialization.
| livenessProbe: | ||
| httpGet: | ||
| path: / | ||
| port: http | ||
| path: /health/live | ||
| port: management | ||
| initialDelaySeconds: 120 | ||
| periodSeconds: 15 | ||
| timeoutSeconds: 5 | ||
| failureThreshold: 5 | ||
| readinessProbe: | ||
| httpGet: | ||
| path: /realms/master | ||
| port: http | ||
| path: /health/ready | ||
| port: management | ||
| initialDelaySeconds: 60 | ||
| timeoutSeconds: 1 | ||
| periodSeconds: 10 | ||
| timeoutSeconds: 5 | ||
| failureThreshold: 3 |
There was a problem hiding this comment.
For applications with long startup times like Keycloak, using a startupProbe is a more robust approach than setting a long initialDelaySeconds on the liveness and readiness probes. A startup probe defers other probes until the application has successfully started, preventing the pod from being killed prematurely. This also allows for more responsive liveness checks immediately after startup. Consider replacing the current probe configuration with one that uses a startupProbe.
startupProbe:
httpGet:
path: /health/ready
port: management
failureThreshold: 30
periodSeconds: 10
livenessProbe:
httpGet:
path: /health/live
port: management
periodSeconds: 15
timeoutSeconds: 5
failureThreshold: 5
readinessProbe:
httpGet:
path: /health/ready
port: management
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 3There was a problem hiding this comment.
Good suggestion, applied in d18ed79. Added a startupProbe and removed initialDelaySeconds from both liveness and readiness probes.
Use a startupProbe to defer liveness/readiness checks until Keycloak has fully started, instead of relying on initialDelaySeconds. This is more robust for applications with variable startup times. Co-Authored-By: Claude Opus 4.6 <[email protected]> Signed-off-by: mattia-eleuteri <[email protected]>
|
Successfully created backport PR for |
|
Successfully created backport PR for |
Summary
KC_HEALTH_ENABLED=trueto activate health endpoints on management port/,/realms/master) to management port 9000 (/health/live,/health/ready)Problem
Keycloak 26.x redirects all HTTP requests on port 8080 to the configured
KC_HOSTNAME(HTTPS). Since kubelet does not follow redirects, probes fail with:After consecutive failures, kubelet kills the container → restart → crashloop.
Additionally,
KC_HEALTH_ENABLEDwas not set, so the dedicated health endpoints on the management port (9000) returned 404 even though the management interface was active (viaKC_METRICS_ENABLED=true).Changes
packages/system/keycloak/templates/sts.yaml:KC_HEALTH_ENABLED=trueenv var to activate/health/liveand/health/readyGET /health/liveon port 9000 (wasGET /on 8080)GET /health/readyon port 9000 (wasGET /realms/masteron 8080)Test plan
/health/livereturns{"status":"UP"}(HTTP 200) on port 9000/health/readyreturns{"status":"UP","checks":[{"name":"Keycloak database connections async health check","status":"UP"}]}(HTTP 200)ProbeWarningorKillingevents🤖 Generated with Claude Code