Last active
October 23, 2022 09:16
-
-
Save track3jyo-hama/18c995771ea044d17f227bae79659afa to your computer and use it in GitHub Desktop.
Creating Aurora Cluster by Crossplane
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
## Aurora クラスターに紐づけるサブネットグループを定義 | |
apiVersion: database.aws.crossplane.io/v1beta1 | |
kind: DBSubnetGroup | |
metadata: | |
name: hama-subnet-group | |
spec: | |
forProvider: | |
region: ap-northeast-1 | |
description: "sample group" | |
# テストなのでID直指定だけど実際はRefとかSelectorで。3AZにするか2AZにするかはアプリケーション全体の可用性設計による | |
subnetIds: | |
- "subnet-xxxxxxxxxxxxxxxxx" | |
- "subnet-xxxxxxxxxxxxxxxxx" | |
- "subnet-xxxxxxxxxxxxxxxxx" | |
providerConfigRef: | |
name: aws-provider | |
--- | |
# Aurora クラスターに関連するパラメータ(MySQL でいうmy.cnfに近いイメージ)グループを定義 | |
# 指定しなかったらデフォルトのものが紐づくので別に作るの必須じゃないし、Auroraの場合は既に最適化チューニング(自動計算)されているので基本デフォルトのまま使ってOKだけど、仮に変更が必要になった時は専用のものを用意しておくのがベストなので作っておく | |
# ここではクラスターパラメータグループというクラスターに紐づける用のパラメータグループを作っているけど、紐づけるインスタンス毎(例えばWriterとReader別々)のパラメータグループを指定したい時は DBParameterGroup というリソースを作ってインスタンス側で指定する。詳細はこちら:https://dev.classmethod.jp/articles/aurora-parameter-group-priority/ | |
apiVersion: rds.aws.crossplane.io/v1alpha1 | |
kind: DBClusterParameterGroup | |
metadata: | |
name: hama-clusterparametergroup | |
spec: | |
forProvider: | |
region: ap-northeast-1 | |
dbParameterGroupFamilySelector: | |
engine: aurora-mysql | |
engineVersion: 8.0.mysql_aurora.3.02.1 | |
description: "for MySQL 8.0-compatible Aurora" | |
# パラメータの指定例/ https://github.com/crossplane-contrib/provider-aws/blob/v0.33.0/examples/rds/db-parametergroup.yaml | |
# parameters: | |
# - parameterName: performance_schema | |
# parameterValue: '1' | |
# applyMethod: pending-reboot | |
providerConfigRef: | |
name: aws-provider | |
--- | |
# Auroraクラスターの定義。ここの段階では実際のインスタンスは作られない | |
apiVersion: rds.aws.crossplane.io/v1alpha1 | |
kind: DBCluster | |
metadata: | |
name: hama-aurora-mysql-cluster | |
spec: | |
forProvider: | |
region: ap-northeast-1 | |
engine: aurora-mysql | |
# aws rds describe-db-engine-versions --engine aurora-mysql --query "DBEngineVersions[].EngineVersion" で一覧取れます | |
engineVersion: 8.0.mysql_aurora.3.02.1 | |
# 上で作ったサブネットグループと関連づけ | |
dbSubnetGroupNameRef: | |
name: hama-subnet-group | |
# 上で作ったパラメータグループと関連づけ | |
dbClusterParameterGroupNameRef: | |
name: hama-clusterparametergroup | |
# インスタンスに紐づけるセキュリティグループを指定する。サンプルなのでID直指定ですが実際はRefとかSelector使ってください | |
vpcSecurityGroupIDs: | |
- "sg-xxxxxxxxxxxxxxxxx" | |
masterUsername: admin | |
# マスターユーザーのパスワードをK8s のシークレットで指定しています。YamlにBase64暗号化のパスワード直書きしたくなかったので、autogeneratePasswordでコントローラー側で自動生成させた(Secretが裏で作られます) | |
masterUserPasswordSecretRef: | |
name: hama-aurora-mysql-cluster | |
namespace: crossplane-system | |
key: password | |
autogeneratePassword: true | |
databaseName: auroradb | |
# この辺のパラメータはセキュリティポリシーなど自社の方針に合わせて設定してください | |
backupRetentionPeriod: 30 | |
copyTagsToSnapshot: true | |
deletionProtection: true | |
enableCloudwatchLogsExports: ["error", "slowquery"] | |
storageEncrypted: true | |
kmsKeyID: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx" | |
applyImmediately: true | |
providerConfigRef: | |
name: aws-provider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# クラスターに紐づける実際のインスタンスを作ります。Crossplaneには現在Read Replica作るとかそういう概念がないので、一個目に作ったインスタンスがWriter、それ以降がReaderが作られる | |
apiVersion: rds.aws.crossplane.io/v1alpha1 | |
kind: DBInstance | |
metadata: | |
name: hama-aurora-mysql-writer | |
spec: | |
forProvider: | |
region: ap-northeast-1 | |
# AZ指定して作りたい時とかはインスタンス毎にAZ指定可能 | |
# availabilityZone: | |
dbInstanceClass: db.r5.large | |
engine: aurora-mysql | |
engineVersion: 8.0.mysql_aurora.3.02.1 | |
# どのクラスターのインスタンスとして起動するか指定 | |
dbClusterIdentifierRef: | |
name: hama-aurora-mysql-cluster | |
# パブリックアクセスはOff | |
publiclyAccessible: false | |
# Performance Insights 周りを有効化しています。個人的には使って欲しい機能ですがコスト次第でOffってもらってもいいです。RetentionPeriodなどは運用しながら調整してみてください | |
enablePerformanceInsights: true | |
performanceInsightsKMSKeyID: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx" | |
performanceInsightsRetentionPeriod: 372 | |
providerConfigRef: | |
name: aws-provider | |
--- | |
apiVersion: rds.aws.crossplane.io/v1alpha1 | |
kind: DBInstance | |
metadata: | |
name: hama-aurora-mysql-reader1 | |
spec: | |
forProvider: | |
region: ap-northeast-1 | |
# availabilityZone: | |
dbInstanceClass: db.r5.large | |
engine: aurora-mysql | |
engineVersion: 8.0.mysql_aurora.3.02.1 | |
dbClusterIdentifierRef: | |
name: hama-aurora-mysql-cluster | |
publiclyAccessible: false | |
enablePerformanceInsights: true | |
performanceInsightsKMSKeyID: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx" | |
performanceInsightsRetentionPeriod: 372 | |
providerConfigRef: | |
name: aws-provider | |
--- | |
apiVersion: rds.aws.crossplane.io/v1alpha1 | |
kind: DBInstance | |
metadata: | |
name: hama-aurora-mysql-reader2 | |
spec: | |
forProvider: | |
region: ap-northeast-1 | |
# availabilityZone: | |
dbInstanceClass: db.r5.large | |
engine: aurora-mysql | |
engineVersion: 8.0.mysql_aurora.3.02.1 | |
dbClusterIdentifierRef: | |
name: hama-aurora-mysql-cluster | |
publiclyAccessible: false | |
enablePerformanceInsights: true | |
performanceInsightsKMSKeyID: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx" | |
performanceInsightsRetentionPeriod: 372 | |
providerConfigRef: | |
name: aws-provider |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment