Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 8, 2025

Adds hot spare functionality to provide high availability for the critical Keycloak authentication service.

Overview

This implementation adds a secondary Keycloak instance that runs alongside the primary instance, sharing the same database. Apache load balancing with health checks provides automatic failover if the primary instance becomes unavailable.

Key Features

Hot Spare Configuration

  • Added ENABLE_HOT_SPARE and KC_SPARE_HOST_PORT configuration variables
  • Second Keycloak instance runs on port 3124 (configurable)
  • Both instances share the same PostgreSQL database for seamless failover
  • Docker Compose profiles control when hot spare runs

Automatic Failover

  • Apache mod_proxy_balancer provides load balancing between instances
  • Health checks monitor both primary (port 3123) and spare (port 3124) instances
  • Balancer manager interface available at /health/balancer-manager for monitoring
  • Automatic retry and ping configuration for robust failover

Management Tools

  • ./cmds/manage-hot-spare.sh - Enable/disable hot spare configuration
  • ./cmds/health-check.sh - Monitor health of all instances
  • Updated deployment documentation with hot spare procedures

Usage

# Enable hot spare
./cmds/manage-hot-spare.sh enable

# Deploy with hot spare
docker compose --profile hot-spare up -d

# Deploy without hot spare (maintains backward compatibility)
docker compose up -d

# Monitor health
./cmds/health-check.sh

Benefits

  • High Availability: Automatic failover ensures service continuity
  • Zero Downtime: Seamless switching between instances
  • Backward Compatible: Existing single-instance deployments continue to work
  • Easy Management: Simple commands to enable/disable hot spare
  • Monitoring: Built-in health checks for proactive monitoring

Fixes #8.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits July 8, 2025 15:09
Co-authored-by: jrmerz <1852393+jrmerz@users.noreply.github.com>
Co-authored-by: jrmerz <1852393+jrmerz@users.noreply.github.com>
Copilot AI changed the title [WIP] [FEATURE] setup hot spare Implement hot spare configuration for Keycloak high availability Jul 8, 2025
Copilot finished work on behalf of jrmerz July 8, 2025 15:17
Copilot AI requested a review from jrmerz July 8, 2025 15:17
@jrmerz
Copy link
Member

jrmerz commented Jul 8, 2025

@copilot can you set it up so there are two docker compose clusters running on two separate vms. The backup postgres instance will be a read only replicate of the primary. Additionally, can the replicate keycloak UI be set to be read only?

Copy link
Contributor Author

Copilot AI commented Jul 8, 2025

@copilot can you set it up so there are two docker compose clusters running on two separate vms. The backup postgres instance will be a read only replicate of the primary. Additionally, can the repl...

I'll implement the distributed architecture you've requested. This involves creating separate Docker Compose configurations for primary and replica VMs, setting up PostgreSQL streaming replication, and configuring the replica Keycloak instance to be read-only. This will provide true high availability across separate infrastructure. Let me work on these changes.

…oss separate VMs

Co-authored-by: jrmerz <1852393+jrmerz@users.noreply.github.com>
Copilot finished work on behalf of jrmerz July 8, 2025 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] setup hot spare

2 participants