MongoDBUser自定义资源允许您配置用户访问 所需的身份验证和 角色 MongoDB database。
例子
以下示例显示了MongoDBUser自定义资源的资源规范:
1 2 apiVersion: mongodb.com/v1 3 kind: MongoDBUser 4 metadata: 5 name: ldap-user-1 6 spec: 7 username: "uid=mdb0,dc=example,dc=org" 8 db: "$external" 9 mongodbResourceRef: 10 name: ldap-replica-set 11 roles: 12 - db: "admin" 13 name: "clusterAdmin" 14 - db: "admin" 15 name: "readWriteAnyDatabase" 16 - db: "admin" 17 name: "dbAdminAnyDatabase" 18 19 ...
所需的MongoDBUser 资源设置
本部分介绍必须用于所有MongoDBUser资源的设置。
apiVersion类型:字符串
MongoDB Kubernetes 资源模式的版本。
kind类型:字符串
要创建的 MongoDB Kubernetes 资源类型。 将其设置为
MongoDBUser。
metadata.name类型:字符串
人类可读的名称,以便您识别此特定的
MongoDBUser资源。资源名称必须少于或等于 44 个字符。
spec.db类型:字符串
这些用户将访问的MongoDB database的名称。 默认值为
admin。spec.dbsets the user's authentication database. The Kubernetes Operator uses this database to identify the user. It also sets theauthSourceparameter in the generated connection string and names the generated connection string secret.To set the database in the connection string URI path, use spec.connectionStringDatabase.
spec.username类型:字符串
人类可读标签,用于标识向MongoDB database或集合进行身份验证所需的用户。
可选的MongoDBUser 资源设置
MongoDBUser自定义资源可以使用以下设置:
spec.connectionStringDatabase类型:字符串
Kubernetes Operator 为此用户生成的连接字符串的 URI 路径中的数据库名称。读取连接字符串密钥的客户端默认使用此数据库。
spec.connectionStringDatabasechanges the URI path but not authentication, which spec.db controls. For example, a user with aspec.dbofadminand aspec.connectionStringDatabaseofmyappauthenticates againstadminand usesmyappby default:mongodb://my-user:pass@host:27017/myapp?authSource=admin The Kubernetes Operator applies the database to both the
connectionString.standardandconnectionString.standardSrvkeys of the connection string secret.Leaving this setting blank results in an empty URI path. In this case, your client determines the active database-for instance,
mongoshuses``test`` by default.spec.connectionStringSecretName类型:字符串
Operator 创建的连接 密钥的名称。stringKubernetes
当您创建新的MongoDB 数据库用户时, Kubernetes Operator 会自动创建新的Kubernetes 密钥。Kubernetes密钥包含有关新数据库用户的以下信息:
username:数据库用户的用户名password:数据库用户的密码connectionString.standard:标准连接string ,可以让您以此数据库用户的身份连接到数据库。connectionString.standardSrv: DNS 种子列表连接string ,可以让您以此数据库用户的身份连接到数据库。
spec.mongodbResourceRef.name类型:字符串
与此用户关联的MongoDB 资源的名称。 例如,
my-resource。spec.mongodbResourceRef.namespace类型:字符串
The namespace that contains the secret for this user. If unspecified, the Kubernetes Operator keeps connection secrets in the same namespace as the
MongoDBUsercustom resource.spec.passwordSecretKeyRef.name类型:字符串
metadata.name存储用户密码的密钥值。 例如,my-secret-name。spec.passwordSecretKeyRef.key类型:字符串
密钥中包含此MongoDB 数据库用户密码的字段的名称。
要了解更多信息,请参阅 Kubernetes 文档。
spec.roles.db类型:字符串
MongoDB database on which the role can act. For example,
admin.spec.roles.name类型:字符串
要授予数据库用户的角色名称。