Amazon リージョン Aurora PostgreSQL ストレージの使用

Amazon リージョン Aurora PostgreSQL インスタンスは、シングルサイトまたはマルチサイト構成のいずれかで、Keycloak の基盤となるデータベースとして使用できます。現在、これは ROSA 上の Keycloak デプロイメントでのみサポートされています。

Aurora クラスターのデプロイ

Aurora クラスターは、次の env を指定して ./provision/aws/rds/aurora_create.sh を実行することにより、選択した 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 データベースを作成するには、2 つのインスタンスを作成します。スクリプトは現在、作成されたインスタンスに対して 2 つ以上の AZ をサポートしていません。追加のインスタンスはすべて、スクリプトでサポートされている 2 つの AZ に分散されます。スクリプトは、クラスターとすべてのインスタンスが利用可能になるまで待機します。クラスターが既に存在する場合、これを示すメッセージが表示され、スクリプトは終了コード 1 で失敗します。

指定された AURORA_CLUSTER は、AWS リージョンごとに一意であり、「DB クラスター識別子」に概説されている規則に従う必要があります。

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 DB クラスターは、確立されたピアリング接続を持つ 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 デプロイメント名前空間にポッドが作成され、Aurora クラスターとの接続が確立されます。最初の接続時にパスワードプロンプトが表示され、Secret keycloak-db-secret で定義されたパスワードを使用する必要があります。ポッドシェルを終了すると、ポッドは削除されます。

データベースの内容をドロップするには、次のコマンドを実行します。次に、すべてのデータセンター内のすべての 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 VPC 間のすべてのピアリング接続を削除するには、次の 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