使用 Amazon Regional Aurora PostgreSQL 存储
Amazon Regional Aurora PostgreSQL 实例可以用作 Keycloak 的底层数据库,无论是在单站点还是多站点配置中。目前,这仅在 ROSA 上的 Keycloak 部署中受支持。
部署 Aurora 集群
Aurora 集群可以部署到您选择的 AWS 区域,通过执行 ./provision/aws/rds/aurora_create.sh
并使用以下环境变量
AURORA_CLUSTER= # The name of the Aurora cluster
AURORA_REGION= # The AWS region hosting the Aurora cluster
AURORA_INSTANCES= # The number of Aurora db instances to create in the AURORA_REGION, defaults to 1
这将创建 Aurora 集群所需的 VPC、子网和路由,以及所述集群的 $AURORA_INSTANCES
Aurora 实例。要创建多可用区数据库,请创建两个实例。该脚本目前不支持为创建的实例提供两个以上的可用区,所有其他实例都分布在脚本支持的两个可用区中。该脚本会等待直到集群和所有实例都可用。如果集群已存在,则会显示一条消息指示这一点,并且脚本将以退出代码 1 失败。
指定的 |
将 ROSA 集群连接到 Aurora 集群
为了遵循安全最佳实践,Aurora 集群不会通过互联网公开。相反,我们需要在 ROSA 集群 VPC 和 Aurora 集群 VPC 之间建立 对等连接。
要配置此类连接,请使用以下环境变量运行 ./provision/aws/rds/aurora_create_peering_connection.sh
AURORA_CLUSTER= # The name of the Aurora cluster
AURORA_REGION= # The AWS region hosting the Aurora cluster
CLUSTER_NAME= # The name of the ROSA cluster to establish the peering connectin with
AWS_REGION= # The AWS region hosting the ROSA cluster
此项目中的脚本确保所有 Aurora 和 ROSA 集群都配置了非重叠的机器 CIDR。
启用 Aurora PostgreSQL 存储
使用以下设置配置 Aurora 存储
KC_DATABASE=aurora-postgres
KC_DATABASE_URL=aws.example.route.com
KC_DATABASE_URL
应该是 Aurora 写入器实例的暴露端点。可以通过使用以下环境变量执行 ./provision/aws/rds/aurora_endpoint.sh
脚本来获得。
AURORA_CLUSTER= # The name of the Aurora cluster instance
AURORA_REGION= # The AWS region hosting the Aurora cluster
有关所有配置选项的列表,请参阅 自定义部署。
调试 Aurora PostgreSQL
Aurora 数据库集群仅对具有已建立对等连接的 ROSA 集群可访问,因此所有调试连接也必须源自所述集群。将 psql
连接到集群的一个简单方法是执行以下操作
kubectl run -i --tty --rm debug --image=postgres:15 --restart=Never -n <namespace> -- psql -h <....rds.amazonaws.com> -d keycloak -U keycloak
这将在 Keycloak 部署命名空间中创建一个 pod,并与 Aurora 集群建立连接。首次连接时将出现密码提示,您应该使用 Secret keycloak-db-secret
中定义的密码。退出 pod shell 后,pod 将被删除。
要删除数据库的内容,请运行以下命令。然后重启所有数据中心中的所有 Keycloak 节点。
DROP SCHEMA public CASCADE; CREATE SCHEMA public;
断开 ROSA 集群与单个 Aurora 集群的连接
要删除 ROSA 集群与特定 Aurora 集群之间的对等连接,请使用以下环境变量执行 ./provision/aws/rds/aurora_delete_peering_connection.sh
AURORA_CLUSTER= # The name of the Aurora cluster instance
AURORA_REGION= # The AWS region hosting the Aurora cluster
CLUSTER_NAME= # The name of the ROSA cluster to remove the peering connection from
AWS_REGION= # The AWS region hosting the ROSA cluster
断开 ROSA 集群与所有 Aurora 集群的连接
要删除给定区域中 ROSA 和 Aurora VPCS 之间的所有对等连接,请使用以下环境变量执行 ./provision/aws/rds/aurora_delete_peering_connection.sh
AURORA_REGION= # The AWS region hosting the Aurora clusters
CLUSTER_NAME= # The name of the ROSA cluster to remove the peering connection from
AWS_REGION= # The AWS region hosting the ROSA cluster