对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

AtlasDatabaseUser 自定义资源

AtlasDatabaseUser自定义资源配置 Atlas 项目中的数据库用户。 您可以为每个项目(而不是每个集群)创建数据库用户。 因此, AtlasDatabaseUser自定义资源配置包含对AtlasProject自定义资源的引用。 事先创建AtlasProject自定义资源。

重要

自定义资源不再默认删除对象

  • Atlas Kubernetes Operator使用自定义资源配置文件来管理Atlas配置,但从Atlas Kubernetes Operator2.0 开始,您在Kubernetes中删除的自定义资源不再(默认)在Atlas中删除。相反, Atlas Kubernetes Operator只是停止管理Atlas中的这些资源。 AtlasProject示例,如果您在Kubernetes中删除 自定义资源,默认默认, Atlas Kubernetes Operator不再自动从Atlas中删除相应的项目。这种行为更改旨在帮助防止意外删除。 要学习;了解详情,包括如何将此行为恢复为在Atlas Kubernetes Operator.2 0之前使用的默认,请参阅新默认值: Atlas Kubernetes2 Operator.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 Database Users API 执行以下操作之一:

  • 创建新的数据库用户。

  • 更新现有用户。

在创建数据库用户之前,您必须使用单个 字段创建不透明密钥,以日志Atlas password集群数据库。

注意

您必须在 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
说明

connectionStringStandard

公共mongodb://连接URI 。

connectionstringStandardSrv

公共mongodb+srv://连接URI 。

username

标识数据库用户的名称。

password

数据库用户的密码。

在 Kubernetes 中运行的应用程序可以使用此信息连接到 Atlas 集群。 您可以将密钥作为文件挂载到应用程序 Pod,应用程序进程可以读取这些文件以获取数据。

以下示例显示将密钥安装为环境变量:

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-theuser

  • p1-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 Operator 将从 中删除theuser aws-cluster。它还从 Kubernetes 集群中删除p1-aws-cluster-theuser密钥。

以下示例显示了采用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的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

以下示例显示了使用AmazonAtlasDatabaseUser Web ServicesAmazon 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

类型:字符串

Optional

标签,指示数据库用户是否使用与用户或用户角色关联的 Amazon Web Services (AWS) 身份和访问管理 (IAM) 凭证进行身份验证。如果不指定值,Atlas 将使用 NONE 的默认值。

此参数接受:

无

User who doesn't use AWS IAM authentication.

用户

Amazon Web Services使用与该用户关联的Amazon Web Services IAM 档案进行凭证验证的用户。

ROLE

Amazon Web Services使用与用户角色关联的Amazon Web Services IAM 档案进行凭证验证的用户。

spec.connectionSecret.name

类型:字符串

可选的

不透明密钥的名称,其中包含Atlas Kubernetes Operator用于连接到Atlas 的组织ID和API密钥。如果未指定, 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

类型:字符串

必需

Database against which the database user authenticates. Database users must provide both a username and authentication database to log into 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.description

类型:字符串

Optional

对此数据库用户的描述,最多 100 个字符。

spec.externalProjectRef.id

类型:字符串

可选的

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

类型:字符串

可选的

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身份验证的用户。

用户

使用 Atlas 托管的 OIDC 的用户。

You must specify $external for the spec.databaseName parameter.

spec.passwordSecretRef

类型:字符串

可选的

对包含密码的密钥的引用。 SCRAM-SHA身份验证方法需要此参数。

spec.projectRef.name

类型:字符串

可选的

数据库用户所属项目的名称。 您必须指定现有的AtlasProject 自定义资源。此参数仅适用于属于由同一实例Atlas Kubernetes Operator托管的项目的数据库用户。

对于属于以下任一机构托管的项目的数据库用户:

  • Atlas Kubernetes Operator的不同实例

  • Atlas Kubernetes Operator以外的工具

使用 spec.externalProjectRef.name 。

spec.roles

类型:数组

必需

包含用户角色以及角色适用的数据库或集合的列表。 有关可用参数的完整列表,请参阅 Atlas数据库用户 API。

spec.scopes

类型:数组

Optional

包含创建用户的集群的列表。

spec.scopes.name

类型:字符串

可选的

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

类型:字符串

可选的

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 specified spec.scopes.

spec.username

类型:字符串

必需

人类可读标签,用于标识向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 Web Services IAM凭证进行身份验证的用户的角色(采用Amazon资源名称格式。) 。

spec.x509Type

类型:字符串

Optional

X.509 method by which the database authenticates the provided spec.username. If you don't specify a value, Atlas uses the default value of NONE.

此参数接受:

无

不使用 X.509 身份验证的用户。

托管

使用 Atlas 托管的 X.509 的用户。

You must specify \$external for the spec.databaseName parameter.

客户

使用自管理 X.509 的用户。使用此 x509Type 创建的用户需要在 spec.username 参数中使用公用名 (CN)。要学习;了解更多信息,请参阅 RFC 2253。

You must specify \$external for the spec.databaseName parameter.

有关API提供的配置参数,请参阅Atlas数据库用户API。

Currently, Atlas Kubernetes Operator does not support the following parameters available from the Atlas Database Users API:

  • ldapAuthType

请勿指定以下参数: