Complete implementation for migrating Keycloak version 26 from Windows Server to a containerized cluster hosted on AWS using EKS.
This project provides a comprehensive solution for migrating Keycloak v26 from a Windows Server deployment to a highly available, containerized deployment on AWS Elastic Kubernetes Service (EKS). The solution includes infrastructure as code, backup scripts, migration automation, and monitoring.
- Keycloak v26 Optimized: Specifically designed for Keycloak version 26 with enhanced features
- Production Ready: High availability with multi-AZ deployment and auto-scaling
- Security Focused: Network policies, secrets management, and security best practices
- Complete Automation: End-to-end automation from backup to deployment
- AWS Native: Leverages AWS services for optimal performance and reliability
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β AWS Cloud β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ β
β β EKS Cluster β β RDS (PostgreSQL) β β Application β β
β β β β β β Load Balancer β β
β β βββββββββββββ β β β β β β
β β β Keycloak β β β Multi-AZ β β SSL/TLS β β
β β β v26 Pods β β β Encrypted β β WAF Enabled β β
β β β (3 replicas)β β β Automated β β β β
β β βββββββββββββ β β Backups β β β β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- Keycloak v26 installed and running
- Database access (PostgreSQL/MySQL/SQL Server)
- PowerShell 5.1 or later
- Administrative access to server
- AWS CLI configured with appropriate permissions
- kubectl installed and configured
- Terraform v1.0 or later
- Helm v3.0 or later
- Access to create EKS clusters, RDS instances, VPCs
- EKS cluster management
- RDS instance creation and management
- VPC and networking configuration
- IAM roles and policies
- Application Load Balancer management
- S3 bucket access for backups
# Export realm data (Windows Server)
.\backup\export-keycloak-data.ps1 -KeycloakHome "C:\keycloak" -OutputDir "C:\backup" -AdminPassword "your-admin-password"
# Backup database
.\backup\backup-database.ps1 -DatabaseType postgresql -Server localhost -Database keycloak -Username keycloak -Password "db-password" -OutputDir "C:\backup"# Initialize and deploy infrastructure
cd terraform
terraform init
terraform plan -var="environment=production" -var="cluster_name=keycloak-prod"
terraform apply# Apply Kubernetes manifests
kubectl apply -f kubernetes/namespace.yaml
kubectl apply -f kubernetes/secrets.yaml
kubectl apply -f kubernetes/configmap.yaml
kubectl apply -f kubernetes/deployment.yaml
kubectl apply -f kubernetes/service.yaml
kubectl apply -f kubernetes/ingress.yaml# Run migration script
./migration/import-data.sh -f /path/to/export.json -d /path/to/database.sql -n keycloakkeycloak-migration/
βββ README.md # This file
βββ .github/
β βββ copilot-instructions.md # GitHub Copilot guidelines
βββ terraform/ # Infrastructure as Code
β βββ main.tf # Main Terraform configuration
β βββ variables.tf # Input variables
β βββ outputs.tf # Output values
β βββ terraform.tfvars.example # Example variables
βββ kubernetes/ # Kubernetes manifests
β βββ namespace.yaml # Namespace configuration
β βββ secrets.yaml # Secret management
β βββ configmap.yaml # Keycloak configuration
β βββ deployment.yaml # Keycloak deployment
β βββ service.yaml # Service definitions
β βββ ingress.yaml # Ingress configuration
βββ backup/ # Windows backup scripts
β βββ export-keycloak-data.ps1 # Realm export script
β βββ backup-database.ps1 # Database backup script
βββ migration/ # Migration automation
β βββ import-data.sh # Data import script
βββ docs/ # Documentation
β βββ migration-guide.md # Detailed migration guide
βββ .vscode/ # VS Code configuration
βββ tasks.json # Build and deployment tasks
The deployment includes optimizations for Keycloak v26:
- Enhanced Clustering: JGroups configuration for multi-pod coordination
- Recovery Codes: Support for v26 recovery code authentication
- Fine-grained Authorization: Enhanced authorization capabilities
- Performance Optimizations: JVM tuning and resource optimization
- Token Exchange: Advanced token exchange features
Key configuration options in configmap.yaml:
KC_DB: postgres
KC_DB_URL: jdbc:postgresql://keycloak-db:5432/keycloak
KC_HOSTNAME_STRICT: false
KC_HTTP_ENABLED: true
KC_METRICS_ENABLED: true
KC_HEALTH_ENABLED: true
KC_CACHE_STACK: kubernetes- Network Policies: Restrict pod-to-pod communication
- RBAC: Role-based access control for Kubernetes resources
- Secrets Management: AWS Secrets Manager integration
- TLS Encryption: End-to-end encryption with cert-manager
- Security Headers: Comprehensive security headers in ingress
- Prometheus metrics endpoint enabled
- Custom Keycloak v26 metrics
- Database connection monitoring
- Resource utilization tracking
- Kubernetes liveness and readiness probes
- Database connectivity checks
- External dependency monitoring
- Structured JSON logging
- Centralized log aggregation
- Error tracking and alerting
- Assessment: Evaluate current Keycloak configuration
- Backup: Create comprehensive backups of data and configuration
- Infrastructure: Deploy AWS infrastructure using Terraform
- Validation: Verify infrastructure deployment
- Database Migration: Restore database to AWS RDS
- Application Deployment: Deploy Keycloak v26 on EKS
- Data Import: Import realm configurations and user data
- Validation: Comprehensive testing and validation
- DNS Update: Point domains to new AWS infrastructure
- Monitoring: Activate comprehensive monitoring
- Validation: Final end-to-end testing
- Cleanup: Decommission old infrastructure
Database Connection Issues
# Check database connectivity
kubectl exec -n keycloak deployment/keycloak -- nc -zv keycloak-postgresql 5432Pod Startup Issues
# Check pod logs
kubectl logs -n keycloak deployment/keycloak --previous
kubectl describe pod -n keycloak -l app.kubernetes.io/name=keycloakImport Failures
# Validate import file format
jq '.["export-metadata"]["export-format-version"]' export.jsonMemory Optimization
- Increase JVM heap size for large datasets
- Adjust database connection pool settings
- Configure horizontal pod autoscaling
Network Optimization
- Use Application Load Balancer with session affinity
- Configure proper readiness and liveness probes
- Optimize database query performance
- Encryption at rest for RDS
- Encryption in transit for all communications
- Regular security updates and patches
- Multi-factor authentication for admin access
- Role-based access control
- Audit logging for all administrative actions
- Private subnets for database and application
- Web Application Firewall (WAF) protection
- DDoS protection via AWS Shield
- Horizontal Pod Autoscaler (HPA) configuration
- Cluster autoscaling for EKS nodes
- Database read replicas for performance
- Vertical Pod Autoscaler (VPA) for resource optimization
- Instance type optimization
- Storage scaling for RDS
- Right-sizing of EC2 instances
- Reserved instances for predictable workloads
- Spot instances for development environments
- AWS Cost Explorer integration
- Resource tagging for cost allocation
- Automated cost alerts
- Daily RDS snapshots with 30-day retention
- Application configuration backups to S3
- Cross-region replication for disaster recovery
- Point-in-time recovery for RDS
- Application state restoration
- Disaster recovery runbooks
Contributions are welcome! Please read the contributing guidelines and submit pull requests for any improvements.
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Check the troubleshooting section
- Review the migration guide in
/docs - Open an issue for bug reports or feature requests
Note: This migration solution is specifically optimized for Keycloak v26. Ensure compatibility before using with other versions.