使用 Amazon 區域 Aurora PostgreSQL 儲存空間

Amazon 區域 Aurora PostgreSQL 執行個體可用於單一或多站點組態中 Keycloak 的底層資料庫。目前,這僅支援在 ROSA 上部署的 Keycloak。

部署 Aurora 叢集

可以使用以下 env 執行 ./provision/aws/rds/aurora_create.sh,將 Aurora 叢集部署到您選擇的 AWS 區域

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 執行個體。若要建立多 AZ 資料庫,請建立兩個執行個體。目前,該腳本不支援為建立的執行個體使用超過兩個 AZ,所有其他執行個體都將分配到該腳本支援的兩個 AZ。該腳本會等待直到叢集和所有執行個體都可用。如果叢集已存在,則會顯示一則訊息,指出此情況,並且該腳本將以結束代碼 1 失敗。

指定的 AURORA_CLUSTER 在每個 AWS 區域中必須是唯一的,並且必須遵循 「資料庫叢集識別碼」 所概述的慣例。

將 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 寫入器執行個體的公開端點。這可以透過使用以下 env 執行 ./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;

從個別 Aurora 叢集斷開 ROSA 叢集的連線

若要移除 ROSA 叢集與特定 Aurora 叢集之間的對等連線,請使用以下 env 執行 ./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

從所有 Aurora 叢集斷開 ROSA 叢集的連線

若要移除指定區域中 ROSA 和 Aurora VPCS 之間的所有對等連線,請使用以下 env 執行 ./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

刪除 Aurora 叢集

在刪除 Aurora 叢集之前,首先必須移除與 ROSA 叢集建立的所有對等連線。

若要移除 Aurora 叢集,請使用以下 env 執行 ./provision/aws/rds/aurora_delete.sh

AURORA_CLUSTER= # The name of the Aurora cluster instance
AURORA_REGION= # The AWS region hosting the Aurora cluster