Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Keycloak v26 Migration to AWS

Complete implementation for migrating Keycloak version 26 from Windows Server to a containerized cluster hosted on AWS using EKS.

🎯 Overview

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.

Key Features

  • 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

πŸ— Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                           AWS Cloud                             β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚   EKS Cluster   β”‚  β”‚   RDS (PostgreSQL)  β”‚  β”‚  Application    β”‚ β”‚
β”‚  β”‚                 β”‚  β”‚                 β”‚  β”‚  Load Balancer  β”‚ β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”‚                 β”‚  β”‚                 β”‚ β”‚
β”‚  β”‚  β”‚ Keycloak  β”‚  β”‚  β”‚  Multi-AZ      β”‚  β”‚  SSL/TLS        β”‚ β”‚
β”‚  β”‚  β”‚ v26 Pods  β”‚  β”‚  β”‚  Encrypted     β”‚  β”‚  WAF Enabled    β”‚ β”‚
β”‚  β”‚  β”‚ (3 replicas)β”‚  β”‚  β”‚  Automated    β”‚  β”‚                 β”‚ β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  β”‚  Backups       β”‚  β”‚                 β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“‹ Prerequisites

Source Environment (Windows Server)

  • Keycloak v26 installed and running
  • Database access (PostgreSQL/MySQL/SQL Server)
  • PowerShell 5.1 or later
  • Administrative access to server

Target Environment (AWS)

  • 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

Required AWS Permissions

  • 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

πŸš€ Quick Start

1. Backup Current Keycloak Instance

# 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"

2. Deploy AWS Infrastructure

# Initialize and deploy infrastructure
cd terraform
terraform init
terraform plan -var="environment=production" -var="cluster_name=keycloak-prod"
terraform apply

3. Deploy Keycloak on Kubernetes

# 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

4. Import Data

# Run migration script
./migration/import-data.sh -f /path/to/export.json -d /path/to/database.sql -n keycloak

πŸ“ Project Structure

keycloak-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

πŸ”§ Configuration

Keycloak v26 Specific Features

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

Environment Variables

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

Security Configuration

  • 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

πŸ“Š Monitoring and Observability

Metrics Collection

  • Prometheus metrics endpoint enabled
  • Custom Keycloak v26 metrics
  • Database connection monitoring
  • Resource utilization tracking

Health Checks

  • Kubernetes liveness and readiness probes
  • Database connectivity checks
  • External dependency monitoring

Logging

  • Structured JSON logging
  • Centralized log aggregation
  • Error tracking and alerting

πŸ”„ Migration Process

Phase 1: Preparation

  1. Assessment: Evaluate current Keycloak configuration
  2. Backup: Create comprehensive backups of data and configuration
  3. Infrastructure: Deploy AWS infrastructure using Terraform
  4. Validation: Verify infrastructure deployment

Phase 2: Migration

  1. Database Migration: Restore database to AWS RDS
  2. Application Deployment: Deploy Keycloak v26 on EKS
  3. Data Import: Import realm configurations and user data
  4. Validation: Comprehensive testing and validation

Phase 3: Cutover

  1. DNS Update: Point domains to new AWS infrastructure
  2. Monitoring: Activate comprehensive monitoring
  3. Validation: Final end-to-end testing
  4. Cleanup: Decommission old infrastructure

πŸ›  Troubleshooting

Common Issues

Database Connection Issues

# Check database connectivity
kubectl exec -n keycloak deployment/keycloak -- nc -zv keycloak-postgresql 5432

Pod Startup Issues

# Check pod logs
kubectl logs -n keycloak deployment/keycloak --previous
kubectl describe pod -n keycloak -l app.kubernetes.io/name=keycloak

Import Failures

# Validate import file format
jq '.["export-metadata"]["export-format-version"]' export.json

Performance Tuning

Memory 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

πŸ”’ Security Considerations

Data Protection

  • Encryption at rest for RDS
  • Encryption in transit for all communications
  • Regular security updates and patches

Access Control

  • Multi-factor authentication for admin access
  • Role-based access control
  • Audit logging for all administrative actions

Network Security

  • Private subnets for database and application
  • Web Application Firewall (WAF) protection
  • DDoS protection via AWS Shield

πŸ“ˆ Scaling

Horizontal Scaling

  • Horizontal Pod Autoscaler (HPA) configuration
  • Cluster autoscaling for EKS nodes
  • Database read replicas for performance

Vertical Scaling

  • Vertical Pod Autoscaler (VPA) for resource optimization
  • Instance type optimization
  • Storage scaling for RDS

πŸ’° Cost Optimization

Resource Optimization

  • Right-sizing of EC2 instances
  • Reserved instances for predictable workloads
  • Spot instances for development environments

Monitoring Costs

  • AWS Cost Explorer integration
  • Resource tagging for cost allocation
  • Automated cost alerts

πŸ”„ Backup and Recovery

Automated Backups

  • Daily RDS snapshots with 30-day retention
  • Application configuration backups to S3
  • Cross-region replication for disaster recovery

Recovery Procedures

  • Point-in-time recovery for RDS
  • Application state restoration
  • Disaster recovery runbooks

πŸ“š Additional Resources

🀝 Contributing

Contributions are welcome! Please read the contributing guidelines and submit pull requests for any improvements.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ“ž Support

For support and questions:

  1. Check the troubleshooting section
  2. Review the migration guide in /docs
  3. 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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages