AtlasDatabaseUserカスタム リソースは、Atlas プロジェクト内のデータベースユーザーを構成します。 データベースユーザーは、クラスターごとではなく、プロジェクトごとに作成します。 したがって、 AtlasDatabaseUserカスタム リソース構成にはAtlasProjectカスタム リソースへの参照が含まれています。 事前にAtlasProjectカスタム リソースを作成してください。
重要
カスタム リソースはデフォルトでオブジェクトを削除しなくなりました
Atlas Kubernetes Operator はカスタムリソース構成ファイルを使用して Atlas 構成を管理しますが、Atlas Kubernetes Operator2.0 以降、 Kubernetesで削除したカスタム リソースは Atlas で削除されなくなりました(デフォルトでは )。代わりに、Atlas Kubernetes Operator は Atlas 内のそれらのリソースの管理を停止します。 例、 Kubernetesで カスタム リソースを削除すると、デフォルトでは、Atlas Kubernetes Operator は Atlas
AtlasProjectから対応するプロジェクトを自動的に削除しなくなります。この動作の変更は、誤ってまたは予期せずに削除されるのを防ぐことを目的としています。 この動作を Atlas Kubernetes Operator. 以前に使用されていたデフォルトに戻す方法などの詳細については、「2 0新しいデフォルト: Atlas Kubernetes Operator. の削除保護2 0」を参照してください。同様に、Atlas Kubernetes Operator を使用してKubernetesの Atlasプロジェクトからチームを削除しても、Atlas Kubernetes Operator は Atlas からチームを削除しません。
デフォルトのAtlas 構成値が暗黙的に使用されるのを避けるために、必要な構成の詳細を明示的に定義します。 場合によっては、Atlas のデフォルトを継承すると調整ループが発生し、カスタムリソースが
READY状態に達しなくなります。 例、含まれている例に示すように、AtlasDeploymentカスタムリソースで必要なオートスケーリング動作を明示的に定義すると、カスタムリソース内の静的インスタンスサイズが、オートスケーリングが有効になっている Atlas 配置に繰り返し適用されないことが保証されます。autoScaling: diskGB: enabled: true compute: enabled: true scaleDownEnabled: true minInstanceSize: M30 maxInstanceSize: M40
次の例えには、 AtlasProjectカスタム リソースへの参照が示されています。
spec: projectRef: name: my-project
Atlas Kubernetes Operator は、Atlas のデータベースユーザー構成が Kubernetes の構成と一致することを確認します。
Atlas Kubernetes Operator は、Atlasデータベースユーザー APIを使用して次のいずれかのアクションを実行します。
新しいデータベースユーザーを作成します。
既存のユーザーを更新します。
データベースユーザーを作成する password前に、Atlas クラスターデータベースにログための単一の フィールドを含む opaque シークレット を作成する必要があります。
注意
AtlasDatabaseUser カスタムリソースが配置されているのと同じ名前空間にシークレットを作成する必要があります。
次の例では、 シークレットを作成しています。
kubectl create secret generic the-user-password --from-literal="password=P@@sword%"
Atlas Kubernetes Operator atlas.mongodb.com/type=credentialsは、不要な シークレット の監視を回避するために、ラベル のシークレットのみを監視します。
次の例ではシークレットにラベルを付けます。
kubectl label secret the-user-password atlas.mongodb.com/type=credentials
接続シークレット
Atlas Kubernetes Operator が Atlas でデータベースユーザーを正常に作成または更新すると、Atlas Kubernetes Operator は、 AtlasDatabaseUserカスタム リソースが配置されている同じ名前空間に接続シークレットを作成または更新します。
接続シークレットには、次のパラメータを含む Atlas クラスターに接続するために必要なすべての情報が含まれています。
Parameter | 説明 |
|---|---|
| パブリック |
| パブリック |
| データベースユーザーを識別する名前。 |
| データベースユーザーのパスワード。 |
Kubernetes で実行されているアプリケーションは、この情報を使用して Atlas クラスターに接続できます。 シークレットを ファイルとしてアプリケーション ポッドにマウントでき、アプリケーション プロセスはこれらのファイルを読み取ってデータを取得できます。
次の例では、シークレットを環境変数としてマウントしています。
spec: containers: - name: test-app env: - name: "CONNECTIONSTRING" valueFrom: secretKeyRef: name: project-cluster-basic-theuser key: connectionStringStandardSrv
次の例では、シークレットを ファイルとしてマウントする方法を示しています。
spec: containers: - name: test-app volumeMounts: - mountPath: /var/secrets/ name: theuser-connection volumes: - name: theuser-connection secret: secretName: project-cluster-basic-theuser
By default, Atlas Kubernetes Operator creates the database user connection secret for each cluster in the same project that the AtlasDatabaseUser references. You can change this behavior with the spec.scopes parameter. This parameter restricts the clusters where the database user gets created. The name of the connection secret uses the following format: <project_name>-<cluster_name>-<db_user_name>.
例
プロジェクトとクラスター
次の例は、Atlas プロジェクトとそれを参照するクラスターを示しています。
apiVersion: atlas.mongodb.com/v1 kind: AtlasProject metadata: name: my-project spec: name: p1 projectIpAccessList: - ipAddress: "192.0.2.15" comment: "IP address for Application Server A" apiVersion: atlas.mongodb.com/v1 kind: AtlasDeployment metadata: name: my-aws-cluster spec: name: aws-cluster projectRef: name: my-project providerSettings: instanceSizeName: M10 providerName: AWS regionName: US_EAST_1 apiVersion: atlas.mongodb.com/v1 kind: AtlasDeployment metadata: name: my-gcp-cluster spec: name: gcp-cluster projectRef: name: my-project providerSettings: instanceSizeName: M10 providerName: GCP regionName: EASTERN_US
スコープのないデータベースユーザー
The following example shows an AtlasDatabaseUser custom resource specification with spec.scopes omitted:
apiVersion: atlas.mongodb.com/v1 kind: AtlasDatabaseUser metadata: name: my-database-user spec: description: "User for the reporting application." roles: - roleName: readWriteAnyDatabase databaseName: admin projectRef: name: my-project username: theuser passwordSecretRef: name: the-user-password
このカスタム リソースを作成すると、Atlas Kubernetes Operator は次のシークレットを作成します。
p1-aws-cluster-theuserp1-gcp-cluster-theuser
スコープを持つデータベースユーザー
The following example shows an AtlasDatabaseUser custom resource specification with spec.scopes set to the Google Cloud cluster only:
apiVersion: atlas.mongodb.com/v1 kind: AtlasDatabaseUser metadata: name: my-database-user spec: roles: - roleName: "readWriteAnyDatabase" databaseName: "admin" projectRef: name: my-project username: theuser passwordSecretRef: name: the-user-password scopes: - type: CLUSTER name: gcp-cluster
このカスタム リソースを更新すると、Atlas Kubernetes Operatortheuser はaws-cluster から を削除します。また、Kubernetes クラスターからp1-aws-cluster-theuserシークレットも削除されます。
X.509 認証を持つデータベースユーザー
次の例は、 X.509 認証を使用したAtlasDatabaseUserのカスタム リソース仕様を示しています。
apiVersion: atlas.mongodb.com/v1 kind: AtlasDatabaseUser metadata: name: my-database-user spec: username: CN=my-x509-authenticated-user,OU=organizationalunit,O=organization databaseName: "\$external" x509Type: "CUSTOMER" roles: - roleName: "readWriteAnyDatabase" databaseName: "admin" projectRef: name: my-project
OIDC 認証を持つデータベースユーザー
次の例では、 OIDCを使用したAtlasDatabaseUserのカスタム リソース仕様を示しています。
apiVersion: atlas.mongodb.com/v1 kind: AtlasDatabaseUser metadata: name: my-database-user spec: roles: - roleName: "readWriteAnyDatabase" databaseName: "admin" projectRef: name: my-project username: my-oidc-group-id/my-idp-group-name oidcAuthType: IDP_GROUP
AWS IAM 認証を持つデータベースユーザー
次の例は、AtlasDatabaseUser AmazonAmazon Web Services Web Services IAM を使用した カスタムリソース仕様を示しています。
apiVersion: atlas.mongodb.com/v1 kind: AtlasDatabaseUser metadata: name: my-database-user spec: username: arn:aws:iam::123456789012:user/johndoe databaseName: "$external" roles: - roleName: "readWriteAnyDatabase" databaseName: "admin" projectRef: name: my-project awsIamType: USER
パラメーター
This section describes some of the key AtlasDatabaseUser custom resource parameters available. For a full list of parameters available, see the Atlas Database Users API. Refer to these descriptions, the available examples, and the API documentation to customize your specifications.
spec.awsIamType型: string
任意
データベースユーザーが、ユーザーに関連付けられた AWS IAM(Identity and Access Management、ID とアクセス管理)認証情報で認証されるか、またはユーザーのロールで認証されるかを示すラベル。値を指定しない場合、Atlas は
NONEのデフォルト値を使用します。このパラメーターは以下を受け入れます。
なし
User who doesn't use AWS IAM authentication.
USER
ユーザーに関連付けられたAmazon WebAmazon Web Services Services IAM 認証情報で認証するユーザー。
ROLE
Amazon Web Servicesユーザーのロールに関連付けられたAmazon Web Services IAM 認証情報で認証するユーザー。
spec.connectionSecret.name型: string
条件付き
Atlas Kubernetes Operator が Atlas に接続するために使用する組織IDとAPIキーを含む opaque secret の名前。指定されていない場合、Atlas Kubernetes Operator は次のいずれかにフォールバックします。
親
atlasProjectのspec.connectionSecretRef.nameパラメータデフォルトの
globalシークレット(親atlasProjectに対してspec.connectionSecretRef.nameが未定義の場合)
このパラメータは独立した CRD に必須です。
Atlas Kubernetes Operator
atlas.mongodb.com/type=credentialsは、不要な シークレット の監視を回避するために、ラベル のシークレットのみを監視します。次の例ではシークレットにラベルを付けます。
kubectl label secret the-user-password atlas.mongodb.com/type=credentials
spec.databaseName型: string
必須
データベースユーザーが認証するデータベース。 データベースユーザーは、MongoDB にログインするためにユーザー名と認証データベースの両方を提供する必要があります。
If the database user authenticates with SCRAM-SHA, this value must be
admin.データベース ユーザーがX.509で認証される場合、この値は
\$externalである必要があります。If the database user authenticates with OpenID Connect, this value must be
$external.
spec.externalProjectRef.id型: string
条件付き
ID of the project to which the database user belongs. You must specify the project ID of an existing Atlas Project. This parameter is required for database users who belong to projects managed by either:
Atlas Kubernetes Operator の別のインスタンス
Atlas Kubernetes Operator 以外のツール
Atlas Kubernetes Operator の同じインスタンスによって管理されるプロジェクトに属するデータベースユーザーの場合、
spec.externalProjectRef.idを使用しない場合はspec.projectRef.nameを使用します。
spec.oidcAuthType型: string
条件付き
OIDC method by which the database authenticates the provided
spec.username.If the database user authenticates with OpenID Connect, this value must be
IDP_GROUP.このパラメーターは以下を受け入れます。
なし
OIDC認証を使用しないユーザー。
USER
Atlas が管理する OIDC を使用するユーザー。
You must specify
$externalfor thespec.databaseNameparameter.
spec.projectRef.name型: string
条件付き
データベースユーザーが属するプロジェクトの名前。 既存の
AtlasProjectカスタム リソース を指定する必要があります。このパラメーターは、同じインスタンスAtlas Kubernetes Operator によって管理されるプロジェクトに属するデータベースユーザーにのみ適用されます。次のいずれかによって管理されるプロジェクトに属するデータベースユーザーの場合、次のいずれかによって管理されます。
Atlas Kubernetes Operator の別のインスタンス
Atlas Kubernetes Operator 以外のツール
spec.externalProjectRef.nameを使用します。
spec.rolesタイプ: 配列
必須
ユーザーのロールと、ロールが適用されるデータベースまたはコレクションが格納されたリスト。 使用可能なパラメーターの完全なリストについては、「 Atlas Database Users API 」を参照してください。
spec.scopes.name型: string
条件付き
Human-readable label that identifies the cluster that the database user can access. You must specify this parameter if you specified
spec.scopes.
spec.scopes.type型: string
条件付き
Human-readable label that identifies the resource type that the database user can access. Atlas Kubernetes Operator currently supports only
CLUSTER. You must specify this parameter if you specifiedspec.scopes.
spec.username型: string
必須
MongoDB database またはコレクションへの認証に必要なユーザーを識別する、人間が判読可能なラベル。
If the database user authenticates with OpenID Connect, this value must be your Atlas OIDC IdP followed by a forward slash
/and your IdP group name.データベースユーザーがAmazon Web Services IAM 認証情報で認証する場合、この値はAmazon Web Services IAM 認証情報で認証されるユーザー、またはAmazon Amazon Web Services IAM 認証形式で認証されるユーザーのロールである必要があります 。
spec.x509Type型: string
任意
X.509 method by which the database authenticates the provided
spec.username. If you don't specify a value, Atlas uses the default value ofNONE.このパラメーターは以下を受け入れます。
なし
X.509 認証を使用しないユーザー。
MANAGED
Atlas が管理する X.509 を使用するユーザー。
You must specify
\$externalfor thespec.databaseNameparameter.CUSTOMER
自己管理型 X.509
x509Typeを使用するユーザー。この で作成されたユーザーには、spec.usernameパラメータに CN(Common Name、共通名)が必要です。詳細については、 RFC2253 を参照してください。You must specify
\$externalfor thespec.databaseNameparameter.
APIから利用可能な構成パラメーターについては、「 Atlas Database Users API 」を参照してください。
Currently, Atlas Kubernetes Operator does not support the following parameters available from the Atlas Database Users API:
ldapAuthType
次のパラメーターを指定しないでください。
groupIdpasswordSpecify
spec.passwordSecretRefinstead.