注意
对于此页面上提到的所有 Ops Manager,您都可以将其替换为 Cloud Manager。
MongoDB Controllers for Kubernetes Operator 从您写入的规范文件创建Kubernetes StatefulSet。
Kubernetes Operator 在 Kubernetes 中创建 MongoDB 专用资源作为自定义资源。
要管理这些自定义资源,请使用以下进程:
创建或更新一个
MongoDB资源规范。指导MongoDB Controllers for Kubernetes Operator 将其应用到您的Kubernetes环境。因此, Kubernetes Operator 会执行以下操作:
创建已定义的 StatefulSets、服务和其他 Kubernetes 资源。
更新 Ops Manager 部署配置以反映更改。
部署类型 | StatefulSet | StatefulSet 大小 |
|---|---|---|
独立运行的实例 | 1 | 1 Pod |
副本集(Replica Set) | 1 | 1每个成员 Pod |
分片集群 | <numberOfShards> + 2 | 每个 |
Each MongoDB resource uses an object specification in YAML to define the characteristics and settings of the MongoDB object: standalone, replica set, and sharded cluster.
通用的资源设置
每种资源类型都必须使用以下设置:
必需
spec.credentials类型:字符串
必需。您创建的Kubernetes密钥名称,该密钥作为Ops Manager API身份验证凭证,供Kubernetes Operator 与Cloud Manager或Ops Manager通信。
The Ops Manager Kubernetes Secret object holding the Credentials must exist on the same Namespace as the resource you want to create.
重要
Operator 管理对密钥的更改
Kubernetes Operator 会跟踪该 Secret 的任何更改并协调
MongoDB资源的状态。
spec.persistent类型:布尔值
默认:真
警告:授予容器写入持久卷的权限。 Kubernetes Operator 在
securityContext中设置fsGroup = 2000、runAsUser = 2000和runAsNonRoot = true。 Kubernetes Operator 将fsgroup设置为等于runAsUser,以使在容器中运行主进程的用户可写入该卷。要学习;了解更多信息,请参阅Kubernetes文档中的为 Pod 或容器配置安全上下文以及相关讨论。如果重新部署资源无法解决持久卷的问题,联系MongoDB支持部门。如果您不使用持久卷,则在查看此部署的数据时,Disk Usage 和 Disk IOPS 图表将无法显示在 Deployment 页面上的 Processes标签页中,也无法显示在 Metrics 页面中。
spec.version类型:字符串
您在此
MongoDB资源上安装的 MongoDB 版本。Community 版的格式应为
X.Y.Z,Enterprise 版的格式应为X.Y.Z-ent。注意
If you update this value to a later version of MongoDB for your database resources, the feature compatibility version remains at the MongoDB version you're upgrading from to give you the option to downgrade if necessary. If you want the feature compatibility version to match the new MongoDB version, you must manually set
spec.featureCompatibilityVersionto the new version or toAlwaysMatchVersion. To learn more, seespec.featureCompatibilityVersion.
可选的
每个资源必须使用以下设置之一:
spec.opsManager.configMapRef.name类型:字符串
具有Cloud Manager或Ops Manager连接配置的 ConfigMap 的名称。
spec.cloudManager.configMapRef.name设置是此设置的别名,可以用来代替它。此值必须与待创建的资源位于同一命名空间。
重要
Operator 管理对 ConfigMap 的更改
Kubernetes Operator 会跟踪该 ConfigMap 的任何更改并协调
MongoDB资源的状态。
spec.cloudManager.configMapRef.name类型:字符串
Alias for
spec.opsManager.configMapRef.name.
Optional
每种资源类型都可以使用以下设置:
metadata.annotations.mongodb.com/v1.architecture类型:字符串
确定特定部署使用的容器架构:
在运行时下载 MongoDB 二进制文件的默认非静态容器,或
在运行时不可变的静态容器(公共预览版) 。
接受的值为:
staticnon-static
apiVersion: mongodb.com/v1 kind: MongoDB metadata: name: my-project annotations: mongodb.com/v1.architecture: "static"
spec.agent.mongod.auditlogRotate.sizeThresholdMB类型:字符串
轮换前单个日志文件的最大大小。需要将 string 转换为 float64。支持 MB 的分数值。
spec.agent.mongod.auditlogRotate.numTotal类型:整型
MongoDB Ops Manager保留的Atlas 审核日志文件总数。 如果不设立此值,则Atlas 审核日志文件的总数默认为0 。
spec.agent.mongod.auditlogRotate.percentOfDiskspace类型:字符串
这些日志文件应占用的总磁盘空间的最大百分比。string 必须能转换为 float64。
spec.agent.mongod.logRotate.timeThresholdHrs类型:整型
下次轮换之前单个日志文件的最大持续时间(以小时为单位)。 自上次轮换以来的时间。
Ops Manager rotates the log file once the file meets either this
timeThresholdHrsor thespec.agent.mongod.logRotate.sizeThresholdMB.
spec.agent.monitoringAgent.logRotate.sizeThresholdMB类型:整型
在MongoDB Agent轮换监控日志之前,单个日志文件的最大大小(以 MB 为单位)。
spec.agent.readinessProbe.environmentVariables类型:对象
配置以下环境变量,用于控制就绪探针的日志文件:
apiVersion: mongodb.com/v1 kind: MongoDB metadata: name: my-project spec: agent: readinessProbe: environmentVariables: READINESS_PROBE_LOGGER_BACKUPS: 1 READINESS_PROBE_LOGGER_MAX_SIZE: 10 READINESS_PROBE_LOGGER_MAX_AGE: 3 READINESS_PROBE_LOGGER_COMPRESS: true MDB_WITH_AGENT_FILE_LOGGING: false LOG_FILE_PATH: /var/log/mongodb-mms-automation/readiness.log
spec.featureCompatibilityVersion类型:字符串
MongoDB升级后默认为之前的MongoDB主要版本。
限制升级到新的主要版本时发生的数据更改。 示例,如果您从MongoDB 5.0升级到MongoDB 6.0 ,则特征兼容性版本将保持为5.0 ,以便您可以在必要时选择降级。
如果您希望特征兼容性版本与新的MongoDB版本匹配,则必须手动设立
featureCompatibilityVersion设置为新版本。 示例,featureCompatibilityVersion: 6.0。或者,您可以启用
AlwaysMatchVersion选项,以便在升级期间自动更新特征兼容性版本以匹配MongoDB版本。 示例,featureCompatibilityVersion: AlwaysMatchVersion。To learn more about feature compatibility, see
setFeatureCompatibilityVersionin the MongoDB Manual.
spec.clusterDomain类型:字符串
默认值:cluster.local
部署 Kubernetes Operator 的 Kubernetes 集群的域名。当 Kubernetes 创建 StatefulSet 时,Kubernetes 会为每个 Pod 分配一个 FQDN。要更新 Cloud Manager 或 Ops Manager,Kubernetes Operator 使用提供的集群名称计算每个 Pod 的 FQDN。Kubernetes 不提供这些主机名查询用的 API。
警告
如果Kubernetes集群具有默认
cluster.local以外的默认域,则必须设立spec.clusterDomain。如果既不使用默认,也不设立spec.clusterDomain选项, Kubernetes Operator 可能无法按预期运行。
spec.clusterName类型:字符串
默认值:cluster.local
部署 Kubernetes Operator 的 Kubernetes 集群的域名。当 Kubernetes 创建 StatefulSet 时,Kubernetes 会为每个 Pod 分配一个 FQDN。要更新 Cloud Manager 或 Ops Manager,Kubernetes Operator 使用提供的集群名称计算每个 Pod 的 FQDN。Kubernetes 不提供这些主机名查询用的 API。
警告
如果Kubernetes集群具有默认
cluster.local以外的默认域,则必须设立spec.clusterDomain。如果既不使用默认,也不设立spec.clusterDomain选项, Kubernetes Operator 可能无法按预期运行。
spec.service类型:字符串
默认:<resource_name>+"-svc" 和 <resource_name>+"-svc-external"
要创建或用于StatefulSet的Kubernetes服务的名称。如果具有此名称的服务已存在, MongoDB Controllers for Kubernetes Operator 不会删除或重新创建该服务。通过此设置,您可以创建自己的自定义服务,并允许Kubernetes Operator 重复使用这些服务。
spec.logLevel类型:字符串
默认值:INFO
配置 Pod 内自动化代理日志记录的级别。接受的值包括:
DEBUGINFOWARNERRORFATAL
部署特定的资源设置
您可以且必须在 MongoDB 资源规范中使用的其他设置取决于您要创建的 MongoDB 部署项:
独立的设置
注意
All of the Standalone Settings also apply to replica set resources.
spec.additionalMongodConfig类型:集合
启动 MongoDB 进程时需要使用的其他配置选项。
Kubernetes Operator 支持您通过 MongoDB 助手部署的 MongoDB 版本所支持的所有配置选项,但 Kubernetes Operator 会覆盖您为以下任何选项提供的值:
要详细了解 Kubernetes Operator 拥有的配置选项,请参阅 MongoDB Kubernetes Operator 独有设置。
To learn which configuration options you can use, see Advanced Options for MongoDB Deployments in the Ops Manager documentation.
spec.agent.startupOptions类型:集合
您要用来启动 MongoDB 数据库资源的 MongoDB 助手设置。
您必须以键值对形式提供 MongoDB 助手设置。这些值必须是字符串。
有关支持的 MongoDB 助手设置列表,请参阅:
云管理器项目的 MongoDB 代理设置。
使用 Kubernetes Operator 部署的 Ops Manager 版本的 MongoDB 助手设置。
1 2 apiVersion: mongodb.com/v1 3 kind: MongoDB 4 metadata: 5 name: my-standalone 6 spec: 7 version: "8.0.0" 8 service: my-service 9 10 opsManager: 11 configMapRef: 12 name: my-project 13 credentials: my-credentials 14 type: Standalone 15 16 persistent: true 17 agent: 18 startupOptions: 19 maxLogFiles: "30" 20 dialTimeoutSeconds: "40" 21 ...
spec.podSpec类型:对象
包含MongoDB CustomResourceDefinition Pod 规范的对象。
spec.externalAccess类型:集合
适用于外部连接的集群公开规范。要了解如何从 Kubernetes 集群外部连接到您的 MongoDB 资源,请参阅从 Kubernetes 外部连接到 MongoDB 数据库资源。
如果您添加
spec.externalAccess,则 Kubernetes Operator 为副本集中的每个 Pod 创建一个外部服务。外部服务为集群中的每个 MongoDB 数据库 Pod 提供外部入口点。每个外部服务具有选择器,它将外部服务与特定 Pod 相匹配。如果添加此设置时不带任何值,Kubernetes Operator 会创建具有以下默认值的外部服务:
字段值说明Name<pod-name>-svc-external外部服务的名称。您无法更改此值。
TypeLoadBalancer创建外部 LoadBalancer 服务。
Port<Port Number>A port for
mongod.publishNotReadyAddresstrue指定即使 Pod 尚未准备就绪,也会创建 DNS 记录。对于任何数据库Pod,请勿设立为
false。注意
If you set
spec.externalAccess.externalDomain, the external service adds another port (Port Number + 1) for backups.
spec.externalAccess.externalService类型:集合
Specification for overriding the default values in
spec.externalAccess.当您设立
spec.externalAccess设置时, Kubernetes Operator 会自动默认值创建外部负载负载均衡器服务。您可以根据需要覆盖某些值或添加新值。示例,如果您打算创建 NodePort 服务并且不需要负载负载均衡器,则必须在Kubernetes规范中配置覆盖:externalAccess: externalService: annotations: # cloud-specific annotations for the service spec: type: NodePort # default is LoadBalancer # you can specify other spec overrides if necessary 有关 Kubernetes 规范的更多信息,请参阅 Kubernetes 文档中的 ServiceSpec。
spec.externalAccess.externalService.annotations类型:集合
键值对,可让您将特定于云提供商的配置设置添加到部署中的所有集群。要学习;了解更多信息,请参阅Kubernetes云提供商的注释和文档。
您可以使用注解为Kubernetes Operator 部署使用的外部服务指定占位符值。Kubernetes Operator 会自动将这些值替换为正确的值,如下表所述。使用占位符,您可以在每个服务中为特定 Pod 提供特定注释。
值说明{resourceName}Equal to
metadata.name.{namespace}Equal to
metadata.namespace.{podIndex}StatefulSet 分配且当前外部服务所针对的 Pod 的索引。
{podName}等于
{resourceName}-{podIndex}。{statefulSetName}StatefulSet。等于
{resourceName}。{externalServiceName}根据指定的占位符值生成的外部服务名称。 等于
{resourceName}-{podIndex}-svc-external。{mongodProcessDomain}The domain name of the server that is hosting the mongod process. Equal to
spec.externalAccess.externalDomainif specified. Otherwise, equal to the domain used for themongodprocess FQDN.例如,对于进程主机名
mdb-rs-1.example.com,example.com是域名。{mongodProcessFQDN}The
mongodprocess hostname set in the automation configuration.The process hostname depends on your deployment configuration. If you've configured your deployment to use
external domains, the process hostname uses the following format:{resourceName}-{podIndex}.{mongodProcessDomain}例如:
mdb-rs-1.example.com如果您的部署不使用外部域,则进程主机名将使用以下格式:
{resourceName}-{podIndex}.{resourceName}-{podIndex}-svc.{namespace}.svc.cluster.local例如:
mdb-rs-1.mdb-rs-1-svc.ns.svc.cluster.local注意
您必须仅使用表中指定的已知占位符值,并确保占位符不使用空值或 null 值。 此外,您不能将特定于多 Kubernetes 集群部署的占位符用于单个MongoDB资源部署。
否则,Kubernetes Operator 将返回错误。 例如,您可能会遇到以下错误消息:
error replacing placeholders in map with key=external-dns.alpha.kubernetes.io/hostname, value={resourceName}-{podIndex}-{unknownPlaceholder}.{clusterName}-{clusterIndex}.example.com: missing values for the following placeholders: {clusterName}, {clusterIndex}, {unknownPlaceholder}`` 例子
以下示例指定了
{resourceName}、{podIndex}和{namespace}占位符:apiVersion: mongodb.com/v1 kind: MongoDB metadata: name: mdb-rs namespace: ns spec: replicas: 3 externalAccess: externalService: annotations: external-dns.alpha.kubernetes.io/hostname: {resourceName}-{podIndex}-{namespace}.example.com Kubernetes Operator 会根据每个占位符的正确值自动填充外部服务的注释。 例如:
mdb-rs-0-svc-external: annotations: external-dns.alpha.kubernetes.io/hostname: mdb-rs-0-ns.example.com mdb-rs-1-svc-external: annotations: external-dns.alpha.kubernetes.io/hostname: mdb-rs-1-ns.example.com mdb-rs-2-svc-external: annotations: external-dns.alpha.kubernetes.io/hostname: mdb-rs-2-ns.example.com
spec.externalAccess.externalService.spec类型:集合
ServiceSpec 的配置。要学习;了解更多信息,请参阅
spec.externalAccess.externalService。
spec.podSpec.persistence.single类型:集合
让 Kubernetes Operator 创建持久化卷声明,并将数据、事务日志与运行日志的所有三个目录挂载到同一个持久卷。
注意
You must set the values in this collection if
spec.persistent: true.您可以设置此集合或
persistence.multiple集合,但不能同时设置两者。
标量数据类型说明labelSelector字符串
storage字符串
应安装的持久卷的最小大小。此值以整数表示,后跟采用 JEDEC 表示法的存储单位。
默认值为 16Gi。
For example, if standalone deployment in requires 60 gigabytes of storage space, set this value to
60Gi.storageClass字符串
持久卷声明中指定的存储类型。您可以先将此存储类型创建为StorageClass对象,然后再用于此对象规范。
确保将StorageClass
reclaimPolicy设立为Retain。这可确保在删除持久卷声明时保留数据。
spec.podSpec.persistence.multiple.data类型:集合
让 Kubernetes Operator 创建持久卷声明,并将数据目录挂载到自己的持久卷上。
注意
You must set the values in this collection if
spec.persistent: true.您可以设置此集合或
persistence.single集合,但不能同时设置这两个集合。
标量数据类型说明labelSelector字符串
storage字符串
storageClass字符串
独立运行部署所需的存储类型。您可以先将此存储类型创建为 StorageClass对象,然后再用于此对象规范。
确保将StorageClass
reclaimPolicy设立为Retain。这可确保在删除持久卷声明时保留数据。
spec.podSpec.persistence.multiple.journal类型:集合
让 Kubernetes Operator 创建持久卷声明,并将日志目录挂载到自己的持久卷上。
注意
You must set the values in this collection if
spec.persistent: true.您可以设置此集合或
persistence.single集合,但不能同时设置这两个集合。
标量数据类型说明labelSelector字符串
storage字符串
storageClass字符串
独立运行部署所需的存储类型。您可以先将此存储类型创建为 StorageClass对象,然后再用于此对象规范。
确保将StorageClass
reclaimPolicy设立为Retain。这可确保在删除持久卷声明时保留数据。
spec.podSpec.persistence.multiple.logs类型:集合
让 Kubernetes Operator 创建持久卷声明,并将日志目录挂载到自己的持久卷上。
注意
You must set the values in this collection if
spec.persistent: true.您可以设置此集合或
persistence.single集合,但不能同时设置这两个集合。
标量数据类型说明labelSelector字符串
storage字符串
storageClass字符串
独立运行部署所需的存储类型。您可以先将此存储类型创建为 StorageClass对象,然后再用于此对象规范。
确保将StorageClass
reclaimPolicy设立为Retain。这可确保在删除持久卷声明时保留数据。
spec.podSpec.podTemplate类型:集合
MongoDB Controllers for Kubernetes Operator 为MongoDB 数据库资源创建的Kubernetes Pod 的模板。
模板值优先于
spec.podSpec中指定的值。注意
Kubernetes Operator 不会验证您在
spec.podSpec.podTemplate中提供的字段。
spec.podSpec.podTemplate.metadata类型:集合
Kubernetes Operator 的MongoDB控制器为MongoDB 数据库资源创建的Kubernetes Pod 的元数据。
要查看哪些字段可以添加到
spec.podSpec.podTemplate.metadata,请参阅Kubernetes文档。
spec.podSpec.podTemplate.spec类型:集合
Kubernetes Operator 的MongoDB控制器为MongoDB 数据库资源创建的Kubernetes Pod 的规范。
要查看哪些字段可以添加到
spec.podSpec.podTemplate.spec,请参阅Kubernetes PodSpec v1 Core API。注意
在将容器添加到
spec.podSpec.podTemplate.spec.containers时,Kubernetes Operator 将它们添加到 Kubernetes Pod 中。这些容器附加到 pod 中的 MongoDB 数据库资源容器。使用此设置为每个 Pod 指定 CPU 和 RAM 分配。 相关示例请参阅 GitHub 上的示例。
spec.podSpec.podTemplate.spec.affinity.nodeAffinity类型:结构
Kubernetes规则将副本集的 Pod 放置在特定范围的节点上。
spec.podSpec.podTemplate.spec.affinity.podAffinity类型:结构
Kubernetes 规则 来确定多个
MongoDB资源 Pod 是否必须与其他 Pod 共处一地。要学习;了解有关使用案例的更多信息,请参阅Kubernetes文档中的关联和反关联。
副本集设置
注意
All of the Standalone Settings also apply to replica set resources.
以下设置适用于副本集资源类型:
spec.backup类型:集合
The collection container for
spec.backup.mode, which enables continuous backups for MongoDB resources in Kubernetes Operator.
spec.backup.assignmentLabels类型:数组
以逗号分隔的标签列表,用于将备份守护程序、oplog 存储、块存储、S3 快照存储和文件系统存储分配给特定的项目或组。可以使用分配标签指定特定备份存储是否与特定项目相关联。
如果您使用 Kubernetes Operator 设置分配标签,您在 Kubernetes 配置文件中为分配标签设置的值将覆盖 Ops Manager 用户界面中定义的值。您未使用 Kubernetes Operator 设置的分配标签继续使用 Ops Manager 用户界面中设置的值。
注意
If you set this parameter, the API key linked with the value of
spec.credentialsmust have aGlobal Ownerrole.
spec.backup.mode类型:字符串
为 MongoDB 资源启用连续备份。可能的值为
enabled、disabled和terminated。注意
The
spec.backup.modesetting relies on Backup that is enabled in the Ops Manager and requires thatspec.backup.enabledvalue in the Ops Manager resource specification is set totrue.After you enable continuous backups for your MongoDB resource with
spec.backup.mode, you can check the backup status.
spec.backup.encryption.kmip类型:对象
Object that contains the KMIP backup encryption configuration settings. To learn more, see Configure KMIP Backup Encryption for Ops Manager.
spec.backup.snapshotSchedule.dailySnapshotRetentionDays类型:数字
保留每日快照的天数。 您可以设置介于
1和365(含)之间的值。 将值设置为0将禁用此规则。
spec.backup.snapshotSchedule.weeklySnapshotRetentionWeeks类型:数字
保存每周快照的周数。可以设置介于
1和52(含 36)之间的值。将该值设置为0将禁用此规则。
spec.backup.snapshotSchedule.monthlySnapshotRetentionMonths类型:数字
保留每月快照的月数。可以设置介于
1和36(含 36)之间的值。将该值设置为0将禁用此规则。
spec.backup.snapshotSchedule.referenceHourOfDay类型:数字
一天中的 UTC 小时,用于使用 24 小时制安排快照。可以设置介于
0和23(包含)之间的值。
spec.backup.snapshotSchedule.fullIncrementalDayOfWeek类型:字符串
Ops Manager 撷取完整快照的星期几。此设置可确保最近的完整备份。Ops Manager 会将默认值设置为
SUNDAY。
spec.clusterName类型:字符串
默认值:cluster.local
部署 Kubernetes Operator 的 Kubernetes 集群的域名。当 Kubernetes 创建 StatefulSet 时,Kubernetes 会为每个 Pod 分配一个 FQDN。要更新 Cloud Manager 或 Ops Manager,Kubernetes Operator 使用提供的集群名称计算每个 Pod 的 FQDN。Kubernetes 不提供这些主机名查询用的 API。
警告
如果Kubernetes集群具有默认
cluster.local以外的默认域,则必须设立spec.clusterDomain。如果既不使用默认,也不设立spec.clusterDomain选项, Kubernetes Operator 可能无法按预期运行。
spec.connectivity.replicaSetHorizons类型:集合
允许您为客户端应用程序和 MongoDB 助手提供不同的 DNS 设置。Kubernetes Operator 为副本集节点使用水平分割 DNS。此功能允许 Kubernetes 集群内部与 Kubernetes 外部进行通信。
您可以为每台主机添加多个外部映射。
水平分割要求:
确保该数组中的每个值是唯一的。
Make sure that the number of entries in this array matches the value given in
spec.members.Provide a value for the
spec.security.certsSecretPrefixsetting to enable TLS. This method to use split horizons requires the Server Name Indication extension of the TLS protocol.
例子
副本集节点使用在复制配置 (
members[n].host) 中配置的主机名相互通信。example-website域为通过该域连接的客户端提供可选地址。就本示例而言,所述范围的名称是任意的。 您可以将范围命名为任何名称,但要确保属于该范围的所有主机名都相同。
1 2 apiVersion: mongodb.com/v1 3 kind: MongoDB 4 metadata: 5 name: <my-replica-set> 6 spec: 7 members: 3 8 version: "8.0.0" 9 type: ReplicaSet 10 opsManager: 11 configMapRef: 12 name: <configMap.metadata.name> 13 credentials: <mycredentials> 14 persistent: true 15 security: 16 tls: 17 enabled: true 18 connectivity: 19 replicaSetHorizons: 20 - "example-website": "web1.example.com:30907" 21 - "example-website": "web2.example.com:32350" 22 - "example-website": "web3.example.com:31185" 23 ...
spec.externalAccess.externalDomain类型:字符串
用于向外部公开您的副本集部署的外部域。
默认情况下,每个副本集节点使用 Kubernetes Pod 的FQDN (
*.svc.cluster.local) 作为默认主机名。不过,如果您将一个外部域添加到该设置中,副本集将使用作为指定域的子域的主机名。此主机名使用以下格式:<replica-set-name>-<pod-idx>.<externalDomain>例如:
replica-set-1.example.comAfter you deploy the replica set with this setting, the Kubernetes Operator uses the hostname with the external domain to override the
processes[n].hostnamefield in the Ops Manager automation configuration. Then, the MongoDB Agent uses this hostname to connect tomongod.To specify other hostnames for connecting to the replica set, you can use the
spec.connectivity.replicaSetHorizonssetting. However, the following connections still use the hostname with the external domain:The MongoDB Agent to connect to
mongod.
WARNING: Specifying this field changes how Ops Manager registers
mongodprocesses. You can't change the value of this field or anyprocesses[n].hostnamefields in the Ops Manager automation configuration for a running replica set deployment.
spec.memberConfig类型:集合
从
MongoDB资源部署的每个 MongoDB 副本集成员的规范。数组中元素的顺序必须反映副本集中成员的顺序。例如,数组的第一个元素会影响索引为
0的 Pod,第二个元素会影响索引为1的 Pod,依此类推。例子
请考虑三节点副本集的以下示例规范:
spec: memberConfig: - votes: 1 priority: "0.5" tags: tag1: "value1" environment: "prod" - votes: 1 priority: "1.5" tags: tag2: "value2" environment: "prod" - votes: 0 priority: "0.5" tags: tag2: "value2" environment: "prod"
spec.memberConfig.priority类型:字符串
Number that indicates the relative likelihood of a MongoDB replica set member to become the primary.
要增加副本集节点成为主节点的相对可能性,请指定较高的
priority值。要降低副本集节点成为主节点的相对可能性,请指定较低的
priority值。
例如,
memberConfig.priority为1.5的成员比memberConfig.priority为0.5的成员更有可能成为主节点。A member with a
memberConfig.priorityof0is ineligible to become the primary. To learn more, see Member Priority.
spec.memberConfig.tags类型:地图
副本集标签映射,用于将读取和写入操作定向到您的 MongoDB 副本集的特定节点。
spec.memberConfig.votes类型:数字
确定 MongoDB 副本集成员能否在选举中投票。设置为
1将允许成员投票。设置为0会将成员排除在选举之外。
以下设置仅适用于副本集资源类型:
spec.backup.autoTerminateOnDeletion类型:布尔值
Flag that controls whether the Kubernetes Operator stops and terminates the backup when you delete a MongoDB resource. If omitted, the default value is
false. Setting this flag totrueis useful when you want to delete the MongoDB custom resource while thespec.backup.modesetting is set toenabled.
分片集群设置
注意
All of the Replica Set Settings also apply to sharded cluster resources unless otherwise specified.
以下设置仅适用于分片集群资源类型:
spec.backup.snapshotSchedule.clusterCheckpointIntervalMin类型:数字
连续集群检查点之间的分钟数。 此设置仅适用于运行分片的且特征兼容性版本为7.0或更早版本的分MongoDB集群。 此数字决定了分片集群的时间点恢复分片的。 您可以设立值设置为
15、30或60。
spec.configServerCount类型:整型
Required. Number of members in the config server.
spec.configSrv.additionalMongodConfig类型:集合
Kubernetes Operator 支持您通过 MongoDB 助手部署的 MongoDB 版本所支持的所有配置选项,但 Kubernetes Operator 会覆盖您为以下任何选项提供的值:
要详细了解 Kubernetes Operator 拥有的配置选项,请参阅 MongoDB Kubernetes Operator 独有设置。
To learn which configuration options you can use, see Advanced Options for MongoDB Deployments in the Ops Manager documentation.
spec.configSrv.agent类型:集合
MongoDB Agent configuration settings for each config server member.
spec.configSrv.agent.startupOptions类型:集合
MongoDB Agent settings with which you want to start each config server member.
您必须以键值对形式提供 MongoDB 助手设置。这些值必须是字符串。
有关支持的 MongoDB 助手设置列表,请参阅:
云管理器项目的 MongoDB 代理设置。
使用 Kubernetes Operator 部署的 Ops Manager 版本的 MongoDB 助手设置。
1 2 apiVersion: mongodb.com/v1 3 kind: MongoDB 4 metadata: 5 name: my-sharded-cluster-options 6 spec: 7 version: "8.0.0" 8 type: ShardedCluster 9 opsManager: 10 configMapRef: 11 name: my-project 12 credentials: my-credentials 13 persistent: true 14 shardCount: 2 15 mongodsPerShardCount: 3 16 mongosCount: 2 17 configServerCount: 1 18 19 mongos: 20 agent: 21 startupOptions: 22 maxLogFiles: "30" 23 24 configSrv: 25 agent: 26 startupOptions: 27 dialTimeoutSeconds: "40" 28 shard: 29 agent: 30 startupOptions: 31 serverSelectionTimeoutSeconds: "20" 32 ...
spec.configSrvPodSpec类型:对象
MongoDB CustomResourceDefinition 包含配置服务器Pod规范的对象。
spec.configSrvPodSpec.persistence.single类型:集合
让 Kubernetes Operator 创建持久化卷声明,并将数据、事务日志与运行日志的所有三个目录挂载到同一个持久卷。
注意
You must set the values in this collection if
spec.persistent: true.您可以设置此集合或
persistence.multiple集合,但不能同时设置两者。
标量数据类型说明labelSelector字符串
storage字符串
应安装的持久卷的最小大小。此值以整数表示,后跟采用 JEDEC 表示法的存储单位。
默认值为 5Gi。
For example, if each config server member in requires 60 gigabytes of storage space, set this value to
60Gi.storageClass字符串
持久卷声明中指定的存储类型。您可以先将此存储类型创建为StorageClass对象,然后再用于此对象规范。
确保将StorageClass
reclaimPolicy设立为Retain。这可确保在删除持久卷声明时保留数据。
spec.configSrvPodSpec.persistence.multiple.data类型:集合
让 Kubernetes Operator 创建持久卷声明,并将数据目录挂载到自己的持久卷上。
注意
You must set the values in this collection if
spec.persistent: true.您可以设置此集合或
persistence.single集合,但不能同时设置这两个集合。
标量数据类型说明labelSelector字符串
storage字符串
storageClass字符串
每个配置服务器成员所需的存储类型。您可以将此存储类型创建为 StorageClass 对象,然后再在此对象规范中使用。
确保将StorageClass
reclaimPolicy设立为Retain。这可确保在删除持久卷声明时保留数据。
spec.configSrvPodSpec.persistence.multiple.journal类型:集合
让 Kubernetes Operator 创建持久卷声明,并将日志目录挂载到自己的持久卷上。
注意
You must set the values in this collection if
spec.persistent: true.您可以设置此集合或
persistence.single集合,但不能同时设置这两个集合。
标量数据类型说明labelSelector字符串
storage字符串
storageClass字符串
每个配置服务器成员所需的存储类型。您可以将此存储类型创建为 StorageClass 对象,然后再在此对象规范中使用。
确保将StorageClass
reclaimPolicy设立为Retain。这可确保在删除持久卷声明时保留数据。
spec.configSrvPodSpec.persistence.multiple.logs类型:集合
让 Kubernetes Operator 创建持久卷声明,并将日志目录挂载到自己的持久卷上。
注意
You must set the values in this collection if
spec.persistent: true.您可以设置此集合或
persistence.single集合,但不能同时设置这两个集合。
标量数据类型说明labelSelector字符串
storage字符串
storageClass字符串
每个配置服务器成员所需的存储类型。您可以将此存储类型创建为 StorageClass 对象,然后再在此对象规范中使用。
确保将StorageClass
reclaimPolicy设立为Retain。这可确保在删除持久卷声明时保留数据。
spec.configSrvPodSpec.podTemplate类型:集合
MongoDB Controllers for Kubernetes Operator 为每个配置服务器成员创建的Kubernetes Pod 模板。
模板值优先于
spec.configSrvPodSpec中指定的值。注意
Kubernetes Operator 不会验证您在
spec.configSrvPodSpec.podTemplate中提供的字段。
spec.configSrvPodSpec.podTemplate.metadata类型:集合
Metadata for the Kubernetes Pods that the MongoDB Controllers for Kubernetes Operator creates for each config server member.
要查看哪些字段可以添加到
spec.configSrvPodSpec.podTemplate.metadata,请参阅Kubernetes文档。
spec.configSrvPodSpec.podTemplate.spec类型:集合
Kubernetes Operator 的MongoDB控制器为每个配置服务器成员创建的Kubernetes Pod 的规范。
要查看哪些字段可以添加到
spec.configSrvPodSpec.podTemplate.spec,请参阅Kubernetes PodSpec v1 Core API。注意
在您将容器添加到
spec.configSrvPodSpec.podTemplate.spec.containers时,Kubernetes Operator 将它们添加到 Kubernetes Pod 中。这些容器会附加到 Pod 中的每个配置服务器成员容器。使用此设置为每个 Pod 指定 CPU 和 RAM 分配。 相关示例请参阅 GitHub 上的示例。
spec.configSrvPodSpec.podTemplate.spec.affinity.podAffinity类型:集合
Kubernetes 规则 来确定多个
MongoDB资源 Pod 是否必须与其他 Pod 共处一地。要学习;了解有关使用案例的更多信息,请参阅Kubernetes文档中的关联和反关联。
spec.configSrvPodSpec.podTemplate.spec.affinity.nodeAffinity类型:集合
Kubernetes规则将副本集的 Pod 放置在特定范围的节点上。
spec.configSrvPodSpec.podTemplate.spec.affinity.podAntiAffinity类型:字符串
Default: kubernetes.io/hostname
设置规则以将托管
MongoDB资源的Pod分布到不同位置。位置可以是单个节点、机架或地区。默认下, Kubernetes Operator 会尝试将 Pod 分布到不同的节点。
spec.configSrvPodSpec.podTemplate.spec.affinity.podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution.topologyKey类型:字符串
Default: kubernetes.io/hostname
spec.mongodsPerShardCount类型:整型
Required. Number of members per shard.
spec.mongosCount类型:整型
Required. Number of
mongosinstances in the sharded cluster.
spec.mongos.additionalMongodConfig类型:集合
Additional configuration options with which you want to start each mongos instance.
Kubernetes Operator 支持您通过 MongoDB 助手部署的 MongoDB 版本所支持的所有配置选项,但 Kubernetes Operator 会覆盖您为以下任何选项提供的值:
要详细了解 Kubernetes Operator 拥有的配置选项,请参阅 MongoDB Kubernetes Operator 独有设置。
To learn which configuration options you can use, see Advanced Options for MongoDB Deployments in the Ops Manager documentation.
spec.mongos.agent类型:集合
MongoDB Agent configuration settings for each
mongosinstance.
spec.mongos.agent.startupOptions类型:集合
MongoDB Agent settings with which you want to start each
mongosinstance.您必须以键值对形式提供 MongoDB 助手设置。这些值必须是字符串。
有关支持的 MongoDB 助手设置列表,请参阅:
云管理器项目的 MongoDB 代理设置。
使用 Kubernetes Operator 部署的 Ops Manager 版本的 MongoDB 助手设置。
1 2 apiVersion: mongodb.com/v1 3 kind: MongoDB 4 metadata: 5 name: my-sharded-cluster-options 6 spec: 7 version: "8.0.0" 8 type: ShardedCluster 9 opsManager: 10 configMapRef: 11 name: my-project 12 credentials: my-credentials 13 persistent: true 14 shardCount: 2 15 mongodsPerShardCount: 3 16 mongosCount: 2 17 configServerCount: 1 18 19 mongos: 20 agent: 21 startupOptions: 22 maxLogFiles: "30" 23 24 configSrv: 25 agent: 26 startupOptions: 27 dialTimeoutSeconds: "40" 28 shard: 29 agent: 30 startupOptions: 31 serverSelectionTimeoutSeconds: "20" 32 ...
spec.mongosPodSpec类型:对象
包含MongoDB CustomResourceDefinition mongos Pod 规范的对象。
spec.mongosPodSpec.podTemplate类型:集合
MongoDB Controllers for Kubernetes Operator 为每个
mongos实例创建的Kubernetes Pod 模板。模板值优先于
spec.mongosPodSpec中指定的值。注意
Kubernetes Operator 不会验证您在
spec.mongosPodSpec.podTemplate中提供的字段。
spec.mongosPodSpec.podTemplate.metadata类型:集合
Metadata for the Kubernetes Pods that the MongoDB Controllers for Kubernetes Operator creates for each
mongosinstance.要查看哪些字段可以添加到
spec.mongosPodSpec.podTemplate.metadata,请参阅Kubernetes文档。
spec.mongosPodSpec.podTemplate.spec类型:集合
Specifications of the Kubernetes Pods that the MongoDB Controllers for Kubernetes Operator creates for each
mongosinstance.要查看哪些字段可以添加到
spec.mongosPodSpec.podTemplate.spec,请参阅Kubernetes PodSpec v1 Core API。注意
When you add containers to
spec.mongosPodSpec.podTemplate.spec.containers, the Kubernetes Operator adds them to the Kubernetes pod. These containers are appended to eachmongosinstance containers in the pod.使用此设置为每个 Pod 指定 CPU 和 RAM 分配。 相关示例请参阅 GitHub 上的示例。
spec.mongosPodSpec.podTemplate.spec.affinity.nodeAffinity类型:集合
Kubernetes规则将副本集的 Pod 放置在特定范围的节点上。
spec.mongosPodSpec.podTemplate.spec.affinity.podAntiAffinity类型:字符串
Default: kubernetes.io/hostname
设置规则以将托管
MongoDB资源的Pod分布到不同位置。位置可以是单个节点、机架或地区。默认下, Kubernetes Operator 会尝试将 Pod 分布到不同的节点。
spec.mongosPodSpec.podTemplate.spec.affinity.podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution.topologyKey类型:字符串
Default: kubernetes.io/hostname
spec.shardCount类型:整型
Required. Number of shards in the sharded cluster.
spec.shard.additionalMongodConfig类型:集合
Kubernetes Operator 支持您通过 MongoDB 助手部署的 MongoDB 版本所支持的所有配置选项,但 Kubernetes Operator 会覆盖您为以下任何选项提供的值:
要详细了解 Kubernetes Operator 拥有的配置选项,请参阅 MongoDB Kubernetes Operator 独有设置。
To learn which configuration options you can use, see Advanced Options for MongoDB Deployments in the Ops Manager documentation.
spec.shard.agent类型:集合
每个分片集群分片成员的 MongoDB 助手配置设置。
spec.shard.agent.startupOptions类型:集合
MongoDB Agent settings with which you want to start each sharded cluster shard member.
您必须以键值对形式提供 MongoDB 助手设置。这些值必须是字符串。
有关支持的 MongoDB 助手设置列表,请参阅:
云管理器项目的 MongoDB 代理设置。
使用 Kubernetes Operator 部署的 Ops Manager 版本的 MongoDB 助手设置。
1 2 apiVersion: mongodb.com/v1 3 kind: MongoDB 4 metadata: 5 name: my-sharded-cluster-options 6 spec: 7 version: "8.0.0" 8 type: ShardedCluster 9 opsManager: 10 configMapRef: 11 name: my-project 12 credentials: my-credentials 13 persistent: true 14 shardCount: 2 15 mongodsPerShardCount: 3 16 mongosCount: 2 17 configServerCount: 1 18 19 mongos: 20 agent: 21 startupOptions: 22 maxLogFiles: "30" 23 24 configSrv: 25 agent: 26 startupOptions: 27 dialTimeoutSeconds: "40" 28 shard: 29 agent: 30 startupOptions: 31 serverSelectionTimeoutSeconds: "20" 32 ...
spec.shardPodSpec类型:对象
MongoDB CustomResourceDefinition 分片Pod规范的对象。
spec.shardPodSpec.persistence.multiple.data类型:集合
让 Kubernetes Operator 创建持久卷声明,并将数据目录挂载到自己的持久卷上。
注意
You must set the values in this collection if
spec.persistent: true.您可以设置此集合或
persistence.single集合,但不能同时设置这两个集合。
标量数据类型说明labelSelector字符串
storage字符串
storageClass字符串
每个分片集群分片成员所需的存储类型。 您可以将此存储类型创建为 StorageClass 对象,然后再在此对象规范中使用。
确保将StorageClass
reclaimPolicy设立为Retain。这可确保在删除持久卷声明时保留数据。
spec.shardPodSpec.persistence.multiple.journal类型:集合
让 Kubernetes Operator 创建持久卷声明,并将日志目录挂载到自己的持久卷上。
注意
You must set the values in this collection if
spec.persistent: true.您可以设置此集合或
persistence.single集合,但不能同时设置这两个集合。
标量数据类型说明labelSelector字符串
storage字符串
storageClass字符串
每个分片集群分片成员所需的存储类型。 您可以将此存储类型创建为 StorageClass 对象,然后再在此对象规范中使用。
确保将StorageClass
reclaimPolicy设立为Retain。这可确保在删除持久卷声明时保留数据。
spec.shardPodSpec.persistence.multiple.logs类型:集合
让 Kubernetes Operator 创建持久卷声明,并将日志目录挂载到自己的持久卷上。
注意
You must set the values in this collection if
spec.persistent: true.您可以设置此集合或
persistence.single集合,但不能同时设置这两个集合。
标量数据类型说明labelSelector字符串
storage字符串
storageClass字符串
每个分片集群分片成员所需的存储类型。 您可以将此存储类型创建为 StorageClass 对象,然后再在此对象规范中使用。
确保将StorageClass
reclaimPolicy设立为Retain。这可确保在删除持久卷声明时保留数据。
spec.shardPodSpec.podTemplate类型:集合
MongoDB Controllers for Kubernetes Operator 为每个分片集群分片成员创建的Kubernetes Pod 模板。
模板值优先于
spec.shardPodSpec中指定的值。注意
Kubernetes Operator 不会验证您在
spec.shardPodSpec.podTemplate中提供的字段。
spec.shardPodSpec.podTemplate.metadata类型:集合
Kubernetes Operator 的MongoDB控制器为每个分片集群分片成员创建的Kubernetes Pod 的元数据。
要查看哪些字段可以添加到
spec.shardPodSpec.podTemplate.metadata,请参阅Kubernetes文档。
spec.shardPodSpec.podTemplate.spec类型:集合
Kubernetes Operator 的MongoDB控制器为每个分片集群分片成员创建的Kubernetes Pod 的规范。
要查看哪些字段可以添加到
spec.shardPodSpec.podTemplate.spec,请参阅Kubernetes PodSpec v1 Core API。注意
When you add containers to
spec.shardPodSpec.podTemplate.spec.containers, the Kubernetes Operator adds them to the Kubernetes pod. These containers are appended to each sharded cluster shard member containers in the pod.使用此设置为每个 Pod 指定 CPU 和 RAM 分配。 相关示例请参阅 GitHub 上的示例。
spec.shardPodSpec.podTemplate.spec.affinity.podAffinity类型:字符串
Kubernetes 规则 来确定多个
MongoDB资源 Pod 是否必须与其他 Pod 共处一地。要学习;了解有关使用案例的更多信息,请参阅Kubernetes文档中的关联和反关联。
spec.shardPodSpec.podTemplate.spec.affinity.nodeAffinity类型:字符串
Kubernetes规则将副本集的 Pod 放置在特定范围的节点上。
spec.shardPodSpec.podTemplate.spec.affinity.podAntiAffinity类型:字符串
Default: kubernetes.io/hostname
设置规则以将托管
MongoDB资源的Pod分布到不同位置。位置可以是单个节点、机架或地区。默认下, Kubernetes Operator 会尝试将 Pod 分布到不同的节点。
spec.shardPodSpec.podTemplate.spec.affinity.podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution.topologyKey类型:字符串
Default: kubernetes.io/hostname
spec.shardSpecificPodSpec类型:数组
包含每个分片 StatefulSet 覆盖配置的列表。
spec.shardSpecificPodSpec.podTemplate类型:集合
MongoDB Controllers for Kubernetes Operator 为特定分片创建的Kubernetes Pod 的模板。
模板值优先于
spec.shardSpecificPodSpec中指定的值。注意
Kubernetes Operator 不会验证您在
spec.shardSpecificPodSpec.podTemplate中提供的字段。
spec.shardSpecificPodSpec.podTemplate.metadata类型:集合
MongoDB Controllers for Kubernetes Operator 为特定分片创建的Kubernetes Pod 的元数据。
要查看哪些字段可以添加到
spec.shardSpecificPodSpec.podTemplate.metadata,请参阅Kubernetes文档。
spec.shardSpecificPodSpec.podTemplate.spec类型:集合
Kubernetes Operator 的MongoDB控制器为特定分片创建的Kubernetes Pod 的规范。
要查看哪些字段可以添加到
spec.shardSpecificPodSpec.podTemplate.spec,请参阅Kubernetes PodSpec v1 Core API。注意
在将容器添加到
spec.shardSpecificPodSpec.podTemplate.spec.containers时,Kubernetes Operator 将它们添加到 Kubernetes Pod 中。这些容器附加到 Pod 中的特定分片容器。使用此设置为每个 Pod 指定 CPU 和 RAM 分配。 相关示例请参阅 GitHub 上的示例。
spec.shardSpecificPodSpec.podTemplate.spec.affinity.podAffinity类型:字符串
Kubernetes 规则 来确定多个
MongoDB资源 Pod 是否必须与其他 Pod 共处一地。要学习;了解有关使用案例的更多信息,请参阅Kubernetes文档中的关联和反关联。
spec.shardSpecificPodSpec.podTemplate.spec.affinity.podAntiAffinity类型:字符串
Default: kubernetes.io/hostname
设置规则以将托管
MongoDB资源的Pod分布到不同位置。位置可以是单个节点、机架或地区。默认下, Kubernetes Operator 会尝试将 Pod 分布到不同的节点。
spec.shardSpecificPodSpec.podTemplate.spec.affinity.podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution.topologyKey类型:字符串
Default: kubernetes.io/hostname
spec.topology类型:字符串
Optional
默认值:
SingleCluster定义分分片集群的拓扑结构。 无法对现有部署进行更改。 如果设立为
MultiCluster:所有分片集群组件都必须定义
clusterSpecList:spec.mongos.clusterSpecListspec.configSrv.clusterSpecListspec.shard.clusterSpecList
以下字段将被忽略,因为它们的等效值会传递给
spec.<section>.clusterSpecList对象中的每个集群:spec.mongodsPerShardCount定义于spec.shard.clusterSpecList.membersspec.mongosCount定义于spec.mongos.clusterSpecList.membersspec.configServerCount定义于spec.configSrv.clusterSpecList.membersspec.shardOverrides.memberConfig定义于spec.shardOverrides.clusterSpecList.memberConfigspec.shardOverrides.members定义于spec.shardOverrides.clusterSpecList.membersspec.shardOverrides.statefulSet定义于spec.shardOverrides.clusterSpecList.statefulSet
示例:
apiVersion: mongodb.com/v1 kind: MongoDB metadata: name: sc spec: shardCount: 3 # we don't specify mongodsPerShardCount, mongosCount and configServerCount as they don't make sense for multi-cluster topology: MultiCluster type: ShardedCluster version: 7.0.12 cloudManager: configMapRef: name: my-project credentials: my-credentials persistent: true shard: clusterSpecList: - clusterName: member-cluster-0 members: 2 # each shard will have 2 members in cluster 0, unless overriden - clusterName: member-cluster-1 members: 2 - clusterName: member-cluster-2 members: 1 shardOverrides: - shardNames: [sc-2] # this override will apply to the third shard (here, shards are indexed from 0 to 2 as we have 3 shards) clusterSpecList: - clusterName: member-cluster-0 # all other fields are optional, if not provided the fields from matching member cluster from shard.clusterSpecList will be taken by default members: 3 - clusterName: member-cluster-1 # we don't deploy this shard to member-cluster-1 # Note that it is also possible to make it explicit with members: 0 # we don't provide entry for clusterName: member-cluster-1, so it won't be deployed there - clusterName: member-cluster-2 members: 2 configSrv: clusterSpecList: - clusterName: member-cluster-0 members: 2 # config server will have 2 members in this cluster - clusterName: member-cluster-1 members: 1 - clusterName: member-cluster-2 members: 2 mongos: clusterSpecList: - clusterName: member-cluster-0 members: 2 # router will have 2 members in this cluster - clusterName: member-cluster-1 members: 1 以下字段仅与包含
topology=MultiCluster的部署相关:spec.configSrv.clusterSpecList注意
此字段专门用于多集群分片集群部署。
类型:对象数组
如果
topology=MultiCluster,则为必填项用于多集群分片分片集群部署的对象大量,具有以下顶级字段:
clusterName类型:字符串
MongoDB Controllers for Kubernetes Operator 在其中调度 StatefulSet 的集群的名称。
externalAccess类型:集合
用于向外部连接公开多 Kubernetes集群MongoDB 部署的规范。 要学习;了解如何从 Kubernetes集群外部连接到多 Kubernetes集群MongoDB 部署,请参阅从外部KubernetesKubernetes到多集群资源。
这些设置应用于所有集群中的服务。 要在特定集群中覆盖这些全局设置,请使用spec.clusterSpecList.externalAccess.externalService。
如果您添加
spec.externalAccess,则 Kubernetes Operator 为副本集中的每个 Pod 创建一个外部服务。外部服务为集群中的每个 MongoDB 数据库 Pod 提供外部入口点。每个外部服务具有选择器,它将外部服务与特定 Pod 相匹配。如果添加此设置时不带任何值,Kubernetes Operator 会创建具有以下默认值的外部服务:
字段值说明Name<pod-name>-svc-external外部服务的名称。您无法更改此值。
TypeLoadBalancer创建外部 LoadBalancer 服务。
Port<Port Number>A port for
mongod.publishNotReadyAddresstrue指定即使 Pod 尚未准备就绪,也会创建 DNS 记录。对于任何数据库Pod,请勿设立为
false。注意
如果设立spec.clusterSpecList.externalAccess.externalDomain ,则外部服务会添加另一个端口 (
Port Number + 1) 用于备份。
members类型:数字
MongoDB 副本集中的节点数。
memberConfig类型:集合
多分片集群MongoDB 部署中每个MongoDB分片及其成员的规范。
分片对象中元素的分片必须反映副本集成员的顺序。 示例,第一个元素会影响索引
0的 Pod,第二个元素会影响索引1的 Pod,依此类推。例子
请考虑以下具有三个副本集的多 Kubernetes 集群 MongoDB 部署的示例规范:
apiVersion: mongodb.com/v1 kind: MongoDBMultiCluster metadata: name: multi-replica-set spec: version: 8.0.0 type: ReplicaSet duplicateServiceObjects: false credentials: my-credentials opsManager: configMapRef: name: my-project clusterSpecList: - clusterName: cluster1.example.com members: 2 memberConfig: - votes: 1 priority: "0.5" tags: tag1: "value1" environment: "prod" - votes: 1 priority: "1.5" tags: tag2: "value2" environment: "prod" - clusterName: cluster2.example.com members: 1 memberConfig: - votes: 1 priority: "0.5" tags: tag1: "value1" environment: "prod" - clusterName: cluster3.example.com members: 1 memberConfig: - votes: 1 priority: "0.5" tags: tag1: "value1" environment: "prod"
podSpec.persistence类型:集合
Only available in
clusterSpecItemobjects passed tospec.configSrv.clusterSpecListandspec.shard.clusterSpecList. Overrides the existing persistence configuration for a given cluster.
statefulSet类型:集合
为多 Kubernetes集群MongoDB 部署中集群的每个 StatefulSet 提供 StatefulSet 覆盖的配置。要设立适用于多 Kubernetes集群MongoDB 部署中所有集群的全局配置,请参阅 spec.statefulSet.spec.
此设置仅适用于多 Kubernetes 集群 MongoDB 部署中的副本集资源类型。
spec.duplicateServiceObjects注意
此字段专门用于多集群分片集群部署。
类型:布尔值
Optional
默认值:
true如果拓扑结构不是
MultiCluster,则忽略。 适用于所有分片集群组件的服务:mongos、configSrv和shards。- 如果设立为
true: - Kubernetes 操作符会在每个节点集群中从所有 节点集群 创建所有
Pod Services。 - 如果设立为
false: - Kubernetes 操作符仅为每个节点集群中托管的 Pod 创建
Pod Services。
- 如果设立为
spec.mongos.clusterSpecList注意
此字段专门用于多集群分片集群部署。
类型:对象数组
如果
topology=MultiCluster,则为必填项用于多集群分片分片集群部署的对象大量,具有以下顶级字段:
clusterName类型:字符串
MongoDB Controllers for Kubernetes Operator 在其中调度 StatefulSet 的集群的名称。
externalAccess类型:集合
用于向外部连接公开多 Kubernetes集群MongoDB 部署的规范。 要学习;了解如何从 Kubernetes集群外部连接到多 Kubernetes集群MongoDB 部署,请参阅从外部KubernetesKubernetes到多集群资源。
这些设置应用于所有集群中的服务。 要在特定集群中覆盖这些全局设置,请使用spec.clusterSpecList.externalAccess.externalService。
如果您添加
spec.externalAccess,则 Kubernetes Operator 为副本集中的每个 Pod 创建一个外部服务。外部服务为集群中的每个 MongoDB 数据库 Pod 提供外部入口点。每个外部服务具有选择器,它将外部服务与特定 Pod 相匹配。如果添加此设置时不带任何值,Kubernetes Operator 会创建具有以下默认值的外部服务:
字段值说明Name<pod-name>-svc-external外部服务的名称。您无法更改此值。
TypeLoadBalancer创建外部 LoadBalancer 服务。
Port<Port Number>A port for
mongod.publishNotReadyAddresstrue指定即使 Pod 尚未准备就绪,也会创建 DNS 记录。对于任何数据库Pod,请勿设立为
false。注意
如果设立spec.clusterSpecList.externalAccess.externalDomain ,则外部服务会添加另一个端口 (
Port Number + 1) 用于备份。
members类型:数字
MongoDB 副本集中的节点数。
memberConfig类型:集合
多分片集群MongoDB 部署中每个MongoDB分片及其成员的规范。
分片对象中元素的分片必须反映副本集成员的顺序。 示例,第一个元素会影响索引
0的 Pod,第二个元素会影响索引1的 Pod,依此类推。例子
请考虑以下具有三个副本集的多 Kubernetes 集群 MongoDB 部署的示例规范:
apiVersion: mongodb.com/v1 kind: MongoDBMultiCluster metadata: name: multi-replica-set spec: version: 8.0.0 type: ReplicaSet duplicateServiceObjects: false credentials: my-credentials opsManager: configMapRef: name: my-project clusterSpecList: - clusterName: cluster1.example.com members: 2 memberConfig: - votes: 1 priority: "0.5" tags: tag1: "value1" environment: "prod" - votes: 1 priority: "1.5" tags: tag2: "value2" environment: "prod" - clusterName: cluster2.example.com members: 1 memberConfig: - votes: 1 priority: "0.5" tags: tag1: "value1" environment: "prod" - clusterName: cluster3.example.com members: 1 memberConfig: - votes: 1 priority: "0.5" tags: tag1: "value1" environment: "prod"
statefulSet类型:集合
为多 Kubernetes集群MongoDB 部署中集群的每个 StatefulSet 提供 StatefulSet 覆盖的配置。要设立适用于多 Kubernetes集群MongoDB 部署中所有集群的全局配置,请参阅 spec.statefulSet.spec.
此设置仅适用于多 Kubernetes 集群 MongoDB 部署中的副本集资源类型。
spec.shard.clusterSpecList注意
此字段专门用于多集群分片集群部署。
类型:对象数组
如果
topology=MultiCluster,则为必填项用于多集群分片分片集群部署的对象大量,具有以下顶级字段:
clusterName类型:字符串
MongoDB Controllers for Kubernetes Operator 在其中调度 StatefulSet 的集群的名称。
externalAccess类型:集合
用于向外部连接公开多 Kubernetes集群MongoDB 部署的规范。 要学习;了解如何从 Kubernetes集群外部连接到多 Kubernetes集群MongoDB 部署,请参阅从外部KubernetesKubernetes到多集群资源。
这些设置应用于所有集群中的服务。 要在特定集群中覆盖这些全局设置,请使用spec.clusterSpecList.externalAccess.externalService。
如果您添加
spec.externalAccess,则 Kubernetes Operator 为副本集中的每个 Pod 创建一个外部服务。外部服务为集群中的每个 MongoDB 数据库 Pod 提供外部入口点。每个外部服务具有选择器,它将外部服务与特定 Pod 相匹配。如果添加此设置时不带任何值,Kubernetes Operator 会创建具有以下默认值的外部服务:
字段值说明Name<pod-name>-svc-external外部服务的名称。您无法更改此值。
TypeLoadBalancer创建外部 LoadBalancer 服务。
Port<Port Number>A port for
mongod.publishNotReadyAddresstrue指定即使 Pod 尚未准备就绪,也会创建 DNS 记录。对于任何数据库Pod,请勿设立为
false。注意
如果设立spec.clusterSpecList.externalAccess.externalDomain ,则外部服务会添加另一个端口 (
Port Number + 1) 用于备份。
members类型:数字
MongoDB 副本集中的节点数。
memberConfig类型:集合
多分片集群MongoDB 部署中每个MongoDB分片及其成员的规范。
分片对象中元素的分片必须反映副本集成员的顺序。 示例,第一个元素会影响索引
0的 Pod,第二个元素会影响索引1的 Pod,依此类推。例子
请考虑以下具有三个副本集的多 Kubernetes 集群 MongoDB 部署的示例规范:
apiVersion: mongodb.com/v1 kind: MongoDBMultiCluster metadata: name: multi-replica-set spec: version: 8.0.0 type: ReplicaSet duplicateServiceObjects: false credentials: my-credentials opsManager: configMapRef: name: my-project clusterSpecList: - clusterName: cluster1.example.com members: 2 memberConfig: - votes: 1 priority: "0.5" tags: tag1: "value1" environment: "prod" - votes: 1 priority: "1.5" tags: tag2: "value2" environment: "prod" - clusterName: cluster2.example.com members: 1 memberConfig: - votes: 1 priority: "0.5" tags: tag1: "value1" environment: "prod" - clusterName: cluster3.example.com members: 1 memberConfig: - votes: 1 priority: "0.5" tags: tag1: "value1" environment: "prod"
podSpec.persistence类型:集合
Only available in
clusterSpecItemobjects passed tospec.configSrv.clusterSpecListandspec.shard.clusterSpecList. Overrides the existing persistence configuration for a given cluster.
statefulSet类型:集合
为多 Kubernetes集群MongoDB 部署中集群的每个 StatefulSet 提供 StatefulSet 覆盖的配置。要设立适用于多 Kubernetes集群MongoDB 部署中所有集群的全局配置,请参阅 spec.statefulSet.spec.
此设置仅适用于多 Kubernetes 集群 MongoDB 部署中的副本集资源类型。
spec.shardOverrides类型:对象数组
Optional
包含每个分片覆盖项的分片。 每个对象包含以下字段:
shardNames必需
此覆盖适用的分片的名称。
podSpec.PersistenceOptional
定义Kubernetes Operator 如何创建持久卷并将其绑定到分片。 对于
topology=MultiCluster,它为所有成员集群设置持久性设置。 您可以在spec.shardOverrides.clusterSpecList.persistence中为特定成员集群定义持久性设置。additionalMongodConfigOptional
spec.shard.additionalMongodConfig的特定于分片的覆盖。agentOptional
spec.shard.agent的特定于分片的覆盖。statefulSetOptional
spec.shardPodSpec.podTemplate和spec.shard.clusterSpecList.statefulSet的特定于分片的覆盖。membersOptional
仅在
topology=SingleCluster时可用。用于覆盖spec.mongodsPerShardCount的特定于分片的覆盖。memberConfigOptional
仅在
topology=SingleCluster时可用。spec.shard.memberConfig的特定于分片的覆盖。
spec.shardPodSpec.persistence.single类型:集合
让 Kubernetes Operator 创建持久化卷声明,并将数据、事务日志与运行日志的所有三个目录挂载到同一个持久卷。
注意
You must set the values in this collection if
spec.persistent: true.您可以设置此集合或
persistence.multiple集合,但不能同时设置两者。
标量数据类型说明labelSelector字符串
storage字符串
应安装的持久卷的最小大小。此值以整数表示,后跟采用 JEDEC 表示法的存储单位。
默认值为 16Gi。
For example, if each sharded cluster shard member in requires 60 gigabytes of storage space, set this value to
60Gi.storageClass字符串
持久卷声明中指定的存储类型。您可以先将此存储类型创建为StorageClass对象,然后再用于此对象规范。
确保将StorageClass
reclaimPolicy设立为Retain。这可确保在删除持久卷声明时保留数据。
Prometheus 设置
您可以将 Prometheus 与副本集或分片集群结合使用。独立运行的实例资源不支持 Prometheus 监控。要使用 Prometheus 监控单节点部署,请改为部署单节点副本集。要了解更多信息,请参阅部署资源以用于 Prometheus。要查看示例,请参阅用于 Prometheus 的 MongoDB 资源。
当您将 Prometheus 与 MongoDB 资源结合使用时,适用以下设置:
spec.prometheus.passwordSecretRef类型:对象
可选的
包含用于基本 HTTP 身份验证密钥详细信息的对象。如要将 Prometheus 与 MongoDB 资源一起使用,就必须指定此设置。
spec.prometheus.passwordSecretRef.key类型:字符串
Optional
默认值:
"password"人类可读字符串,用于标识存储基本 HTTP 身份验证密码的秘密中的密钥。如果不指定此设置,则使用默认设置。
spec.prometheus.passwordSecretRef.name类型:字符串
可选的
人类可读标签,用于标识用户进行基本 HTTP 身份验证的 密钥。如要将 Prometheus 与 MongoDB 资源一起使用,就必须指定此设置。
spec.prometheus.tlseSecretKeyRef.key类型:字符串
Optional
默认值:
"password"人类可读字符串,用于标识 存储用于 TLS 身份验证的密码的 秘密 中的密钥。如果不指定此设置,则应用默认设置。
安全设置
以下安全设置仅适用于副本集和分片集群资源类型:
spec.security.tls.ca类型:字符串
提供 ConfigMap 的名称,它存储
MongoDB资源的 CA。重要
如果使用自定义 CA 签署
MongoDB资源的 TLS 证书,则必须指定此参数。Kubernetes Operator 要求您在 ConfigMap 中将
MongoDB资源证书命名为ca-pem。
spec.security.certsSecretPrefix类型:字符串
要作为前缀添加到您创建的 Kubernetes 密钥中的文本,这些密钥包含了副本集或分片集群的 TLS 密钥和证书。
您必须在密钥前面加上
<prefix>-<metadata.name>作为前缀。示例,如果调用部署
my-deployment并将前缀设置为mdb,则必须命名用于客户端 TLS 通信 的 TLSmdb-my-deployment-cert秘钥。此外,您必须命名用于内部集群身份验证(如果已启用)mdb-my-deployment-clusterfile的 TLS 密钥。要了解有关命名包含 TLS 证书的密钥的更多信息,请参阅部署副本集中适用于您的部署的主题。
spec.security.tls.additionalCertificateDomains类型:布尔值
应添加到该部署中的每个 Pod 的 TLS 证书的每个域的列表。在您设置该参数时,Kubernetes Operator 转换为 TLS 证书的每个 CSR 都包含一个
<pod name>.<additional cert domain>格式的 SAN。Replica set resources don't need this parameter. Use
spec.connectivity.replicaSetHorizonsinstead.注意
如果您将此参数添加到启用 TLS 的资源,Kubernetes 将在资源达到
Pending状态时显示错误。显示此错误:Please manually remove the |csr| in order to proceed.要解决此问题:删除任何现有的 CSR,以便 Kubernetes 可以生成新的 CSR。如需了解如何删除资源,请参阅 Kubernetes 文档中的删除资源。
在 Kubernetes 生成 CSR 后批准它们。
spec.additionalMongodConfig.net.ssl.mode类型:字符串
默认值:
requireSSL指定用于网络连接的
sslMode。以下是有效选项:值说明allowSSL服务器之间的连接不使用 TLS。对于传入连接,服务器既接受 TLS,也接受非 TLS。
preferSSL服务器之间的连接使用 TLS。对于传入连接,服务器既接受 TLS,也接受非 TLS。
requireSSL服务器仅使用和接受 TLS 加密连接。
spec.additionalMongodConfig.net.tls.disabledProtocols类型:字符串
MongoDB 版本 4.2 新增内容。
禁止使用 TLS 运行的 MongoDB 服务器接受使用一个或多个特定协议的传入连接。要指定多个协议,请输入以逗号分隔的协议列表。例如,
TLS1_0,TLS1_1。此设置可识别以下协议:
TLS1_0、TLS1_1、TLS1_2,以及从 MongoDB 4.0.4(和 3.6.9)开始,还可识别TLS1_3。如果指定了未识别的协议,服务器将无法启动。在 macOS 上,您无法禁用
TLS1_1并同时启用TLS1_0和TLS1_2。您还必须至少禁用TLS1_0或TLS1_2。例如,TLS1_0,TLS1_1在 macOS 上禁用TLS1_2。禁用的协议列表将替换默认的禁用协议列表。
从MongoDB版本 4.0 开始,如果 TLS 1.1+ 在系统上可用, MongoDB将禁用 TLS 1.0。要启用已禁用的 TLS 1.0,请指定
none作为spec.additionalMongodConfig.net.tls.disabledProtocols的值。副本集和分片集群的成员必须至少使用一个共同协议。
spec.security.authentication.enabled类型:布尔值
默认值:
falseSpecifies whether authentication is enabled on the Cloud Manager or Ops Manager project. If set to
true, you must set an authentication mechanism inspec.security.authentication.modes.重要
如果您包含此设置,即使将其设置为
false,Kubernetes Operator 也会管理此 MongoDB 资源的身份验证。当资源规范中存在此设置时,您无法使用 Cloud Manager 或 Ops Manager UI 或 API 配置此资源的身份验证。如果您想使用 Cloud Manager 或 Ops Manager 用户界面或 API 管理身份验证,请忽略此设置。
spec.security.authentication.modes类型:数组
指定MongoDB 部署使用的身份验证机制。有效值为
SCRAM、SCRAM-SHA-1、MONGODB-CR、X509、LDAP和OIDC。我们建议使用SCRAM-SHA-256(SCRAM) 而不是SCRAM-SHA-1。如果指定SCRAM-SHA-1,则还必须指定MONGODB-CR。注意
X.509 内部集群身份验证
To enable X.509 internal cluster authentication for the Cloud Manager or Ops Manager project, set this value to
["X509"]and specify the following settings:provide a value for the
spec.security.certsSecretPrefixsetting.`
If you provide more than one value for
spec.security.authentication.modes, you must also specify a value forspec.security.authentication.agents.mode.
spec.security.authentication.internalCluster类型:字符串
Specifies whether X.509 internal cluster authentication is enabled.
要启用 X.509 内部集群身份验证,请设置为
"X509"。要求指定以下设置:spec.security.authentication.modes: ["X509"]
Kubernetes Operator 接受以下值:
["X509"]:启用 X.509 内部集群身份验证。""或省略:未启用内部集群身份验证。
重要
启用内部集群身份验证后,就无法再将其禁用。
spec.security.authentication.requireClientTLSAuthentication类型:布尔值
默认值:
false指定 MongoDB 主机是否要求客户端使用 TLS 证书进行连接。如果启用 TLS 身份验证,则默认为
true。To enable TLS authentication, provide a value for the
spec.security.certsSecretPrefixsetting.
spec.security.authentication.ldap类型:集合
LDAP 身份验证所需。
Configures LDAP authentication for the Cloud Manager or Ops Manager project. To enable LDAP authentication, set
spec.security.authentication.modesto["LDAP"].
spec.security.authentication.ldap.servers类型:字符串数组
LDAP 身份验证所需。
List of hostnames and ports of the LDAP servers. Specify hostnames with their respective ports in the following format:
spec: security: authentication: ldap: servers: - "<hostname1>:<port1>" - "<hostname2>:<port2>"
spec.security.authentication.ldap.transportSecurity类型:字符串
LDAP 身份验证所需。
指定 LDAP 服务器是否接受 TLS。
如果 LDAP 服务器接受 TLS,请将该值设为
tls。如果 LDAP 服务器不接受 TLS,请将该值留空或设为none。注意
如果指定
none或tls以外的字符串,则 Kubernetes Operator 仍会将该项设置设为tls。
spec.security.authentication.ldap.caConfigMapRef类型:集合
是使用 TLS 进行 LDAP 身份验证所必需的。
ConfigMap,其中包含验证 LDAP 服务器的 TLS 证书的 CA。
spec.security.authentication.ldap.caConfigMapRef.name类型:字符串
是使用 TLS 进行 LDAP 身份验证所必需的。
ConfigMap 的名称,它包含验证 LDAP 服务器的 TLS 证书的 CA。
spec.security.authentication.ldap.caConfigMapRef.key类型:字符串
是使用 TLS 进行 LDAP 身份验证所必需的。
存储验证 LDAP 服务器 TLS 证书的 CA 的字段名称。
spec.security.authentication.ldap.bindQueryUser类型:字符串
LDAP 身份验证所需。
连接到 LDAP 服务器时 MongoDB 绑定到的 LDAP 可分辨名称。
spec.security.authentication.ldap.bindQueryPasswordSecretRef类型:集合
LDAP 身份验证所需。
指定密钥,其中包含 MongoDB 在连接到LDAP 服务器时绑定的密码。
spec.security.authentication.ldap.bindQueryPasswordSecretRef.name类型:字符串
LDAP 身份验证所需。
密钥的名称,该密钥包含了 MongoDB 在连接到 LDAP 服务器时绑定的密码。
密钥 必须仅包含一个用于存储密码的
password字段。
spec.security.authentication.ldap.authzQueryTemplate类型:字符串
是 LDAP 授权所必需的。
由MongoDB执行的 RFC4515 和 RFC4516 LDAP格式查询URL模板,用于获取用户所属的LDAP群组。该查询是相对于
spec.security.authentication.ldap.servers中指定的一托管或多台主机的。您可以在模板中使用以下词元:{USER}- Substitutes the authenticated username, or the
transformedusername, into the LDAP query.
{PROVIDED_USER}- 在 LDAP 查询中替换所提供的用户名(在身份验证或 LDAP 转换之前)。(从 MongoDB 版本 4.2 开始提供)
提示
MongoDB 手册中的 LDAP 查询模板
spec.security.authentication.agents.automationLdapGroupDN类型:字符串
MongoDB 助手用户所属的 LDAP 组的可分辨名称 (DN)。
在以下情况下需要使用此设置:
spec.security.authentication.agents.modeisLDAPorX509.
spec.security.authentication.ldap.userToDNMapping类型:字符串
Maps the username provided to
mongodormongosfor authentication to a LDAP Distinguished Name (DN).提示
security.ldap.userToDNMapping在MongoDB手册中
spec.security.authentication.ldap.userCacheInvalidationInterval类型:整型
指定 MongoDB 等待刷新 LDAP 用户缓存的秒数。默认为 30 秒。
spec.security.authentication.oidcProviderConfigs类型:集合
必需
MongoDB版本必须为 7.0.11+ 或 8.0.0+
仅支持MongoDB Enterprise
注意
当
spec.security.authentication.mode设立为OIDC时,集合中至少有一个元素是必需的。
spec.security.authentication.oidcProviderConfigs.audience类型:字符串
必需
外部身份提供商(IdP) 打算为其提供令牌的实体。输入您在外部 IdP 注册的应用中的受众群体值。如果定义了多个 IdP,则对于共享
issuerURI的每个配置,这必须是唯一值。
spec.security.authentication.oidcProviderConfigs.authorizationMethod类型:字符串
必需
Valid values are
WorkforceIdentityFederationandWorkloadIdentityFederation. Configure single-sign-on for human user access to deployments with Workforce Identity Federation. For programmatic application access to deployments, use Workload Identity Federation. Only one Workforce Identity Federation IdP can be configured per MongoDB resource. To learn more, see Authentication and Authorization with OIDC/OAuth 2.0.
spec.security.authentication.oidcProviderConfigs.authorizationType类型:字符串
必需
有效值为
GroupMembership和UserID。选择GroupMembership以根据 IdP 用户群组成员身份授予授权,或选择UserID以向单个用户授予授权。
spec.security.authentication.oidcProviderConfigs.clientId类型:字符串
必需
已注册应用程序的唯一标识符。输入您在外部身份提供程序中注册的应用的
clientId值。
spec.security.authentication.oidcProviderConfigs.configurationName类型:字符串
必需
标识此配置的唯一标签。此标签对MongoDB Ops Manager用户可见,并在创建用户和角色进行授权时使用。 区分大小写,且只能包含以下字符:
字母数字字符(a 到 z 和 0 到 9 的组合)
连字符 (-)
下划线 (_)
spec.security.authentication.oidcProviderConfigs.groupsClaim类型:字符串
Optional
包含用户主体身份声明的标识符。接受默认值,除非 IdP 使用不同声明。
spec.security.authentication.oidcProviderConfigs.issuerURI类型:字符串
必需
已注册的 IdP应用程序提供的发行者值。MongoDB使用此 URI 查找 OpenID 提供程序配置文档,该文档可在
/.wellknown/open-id-configuration端点中找到。对于MongoDB8.0+,issuerURI和受众的组合必须在 OIDC提供商程序配置中唯一。对于其他MongoDB版本,issuerURI本身必须是唯一的。
spec.security.authentication.oidcProviderConfigs.requestedScopes类型:字符串
Optional
授予用户从授权端点请求数据权限的令牌。仅用于 Workforce Identity Federation授权方法。
spec.security.authentication.oidcProviderConfigs.userClaim类型:字符串
必需
包含用户主体身份声明的标识符。接受默认值,除非 IdP 使用不同声明。
spec.security.authentication.agents.mode类型:字符串
The authentication mechanism that the MongoDB Agents for your MongoDB deployment use. Valid values are
SCRAM,SCRAM-SHA-1,MONGODB-CR,X509,OIDC, andLDAP. The value you specify must also be present inspec.security.authentication.modes. We recommendSCRAM-SHA-256(SCRAM) overSCRAM-SHA-1. If you specifySCRAM-SHA-1, you must also specifyMONGODB-CR.This setting is required if you specified more than one value for
spec.security.authentication.modes.
spec.security.authentication.agents.automationUserName类型:字符串
Name of the user that the MongoDB Agents use to interact with your MongoDB deployment. The username is mapped to an LDAP Distinguished Name (DN) according to
spec.security.authentication.ldap.userToDNMapping. The resulting DN must already exist in your LDAP deployment.This setting is required if
spec.security.authentication.agents.modeisLDAP.
spec.security.authentication.agents.automationPasswordSecretRef类型:集合
包含
spec.security.authentication.agents.automationUserName用户密码的密钥的详细信息。This setting is required if
spec.security.authentication.agents.modeisLDAP.
spec.security.authentication.agents.automationPasswordSecretRef.name类型:字符串
包含
spec.security.authentication.agents.automationUserName用户密码的密钥名称。您必须在部署Kubernetes Operator 的同一命名空间中创建此密钥:kubectl create secret generic ldap-agent-user \ --from-literal="password=<password>" -n <metadata.namespace> This secret must contain one key, the value of which matches the password of the
spec.security.authentication.agents.automationUserNameuser in your LDAP deployment.This setting is required if
spec.security.authentication.agents.modeisLDAP.
spec.security.authentication.agents.automationPasswordSecretRef.key类型:字符串
键入包含
spec.security.authentication.agents.automationUserName中用户密码的spec.security.authentication.agents.automationPasswordSecretRef.name密钥。This setting is required if
spec.security.authentication.agents.modeisLDAP.
spec.security.authentication.agents.clientCertificateSecretRef.name类型:字符串
指定包含 MongoDB Agent 的 TLS 证书的 密钥 。如果省略,则默认为
agent-certs。您必须在部署Kubernetes Operator 的同一命名空间中创建此密钥,并且密钥的类型必须为
kubernetes.io/tls。
spec.security.roles类型:数组
定义用户定义的角色的数组,您可以通过这些角色对 MongoDB 部署进行精细的访问控制。
To enable user-defined roles, the
spec.security.authentication.enabledmust betrue.例子
在此示例中,名为
customRole的用户定义角色允许用户将此角色分配给:在
pets数据库的cats集合中插入文档,以及查找文档并将其插入到
pets数据库的dogs集合中。
1 2 apiVersion: mongodb.com/v1 3 kind: MongoDB 4 metadata: 5 name: <my-replica-set> 6 spec: 7 members: 3 8 version: "8.0.0" 9 type: ReplicaSet 10 opsManager: 11 configMapRef: 12 name: <configMap.metadata.name> 13 credentials: <mycredentials> 14 persistent: true 15 security: 16 authentication: 17 enabled: true 18 modes: 19 - "SCRAM" 20 roles: 21 - role: "customRole" 22 db: admin 23 privileges: 24 - actions: 25 - insert 26 resource: 27 collection: cats 28 db: pets 29 - actions: 30 - insert 31 - find 32 resource: 33 collection: dogs 34 db: pets 35 ...
spec.security.roles.authenticationRestrictions类型:数组
Array that defines the IP address from which and to which users assigned this
spec.security.roles.rolecan connect.
spec.security.roles.authenticationRestrictions.clientSource类型:数组
Array of IP addresses or CIDR blocks from which users assigned this
spec.security.roles.rolecan connect.如果请求来自此数组中不存在的客户端,则 MongoDB Server 会拒绝具有此角色的用户的连接请求。
spec.security.roles.authenticationRestrictions.serverAddress类型:数组
Array of IP addresses or CIDR blocks to which users assigned this
spec.security.roles.rolecan connect.如果客户端请求连接到该数组中不存在的服务器,则 MongoDB 服务器拒绝具有该角色的用户的连接请求。
spec.security.roles.privileges.actions类型:数组
List of actions that users granted this role can perform. For a list of accepted values, see Privilege Actions in the MongoDB Manual for the MongoDB versions you deploy with the Kubernetes Operator.
spec.security.roles.privileges.resource类型:集合
Resources for which the privilege
actionsapply.此集合必须包含以下任一项:
The
spec.security.roles.privileges.resource.clustersetting with a value oftrue.
spec.security.roles.privileges.resource.database类型:字符串
Database for which the privilege
actionsapply.If you provide a value for this setting, you must also provide a value for
spec.security.roles.privileges.resource.collection.
spec.security.roles.privileges.resource.collection类型:字符串
Collection in the
databasefor which the privilegeactionsapply.If you provide a value for this setting, you must also provide a value for
spec.security.roles.privileges.resource.database.
spec.security.roles.privileges.resource.cluster类型:布尔值
默认值:False
Flag that indicates that the privilege
actionsapply to all databases and collections in the MongoDB deployment. If omitted, defaults tofalse.If set to true, do not provide values for
spec.security.roles.privileges.resource.databaseandspec.security.roles.privileges.resource.collection.
示例
以下示例显示了提供所有设置的独立部署的资源规范:
apiVersion: mongodb.com/v1 kind: MongoDB metadata: name: my-standalone spec: version: "8.0.0" service: my-service opsManager: # Alias of cloudManager configMapRef: name: my-project credentials: my-credentials persistent: true type: Standalone additionalMongodConfig: systemLog: logAppend: true verbosity: 4 operationProfiling: mode: slowOp podSpec: persistence: single: storage: "12Gi" storageClass: standard labelSelector: matchExpressions: - {key: environment, operator: In, values: [dev]} podTemplate: metadata: labels: label1: mycustomlabel spec: affinity: podAffinity: requiredDuringSchedulingIgnoredDuringExecution: - labelSelector: matchExpressions: - key: security operator: In values: - S1 topologyKey: failure-domain.beta.kubernetes.io/zone nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/e2e-az-name operator: In values: - e2e-az1 - e2e-az2 podAntiAffinity: preferredDuringSchedulingIgnoredDuringExecution: - podAffinityTerm: topologyKey: "mykey" weight: 50 ...
以下示例显示了提供每个设置的副本集的资源规范:
apiVersion: mongodb.com/v1 kind: MongoDB metadata: name: my-replica-set spec: members: 3 version: "8.0.0" service: my-service opsManager: # Alias of cloudManager configMapRef: name: my-project credentials: my-credentials persistent: true type: ReplicaSet podSpec: persistence: multiple: data: storage: "10Gi" journal: storage: "1Gi" labelSelector: matchLabels: app: "my-app" logs: storage: "500M" storageClass: standard podTemplate: metadata: labels: label1: mycustomlabel spec: affinity: podAffinity: requiredDuringSchedulingIgnoredDuringExecution: - labelSelector: matchExpressions: - key: security operator: In values: - S1 topologyKey: failure-domain.beta.kubernetes.io/zone nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/e2e-az-name operator: In values: - e2e-az1 - e2e-az2 podAntiAffinity: preferredDuringSchedulingIgnoredDuringExecution: - podAffinityTerm: topologyKey: "mykey" weight: 50 security: certsSecretPrefix: "prefix" tls: ca: custom-ca authentication: enabled: true modes: ["X509"] internalCluster: "X509" statefulSet: spec: serviceName: my-service additionalMongodConfig: net: ssl: mode: preferSSL ...
以下示例显示了提供每个设置的分片集群的资源规范:
apiVersion: mongodb.com/v1 kind: MongoDB metadata: name: my-sharded-cluster spec: shardCount: 2 mongodsPerShardCount: 3 mongosCount: 2 configServerCount: 3 version: "8.0.0" service: my-service type: ShardedCluster ## Please Note: The default Kubernetes cluster name is ## `cluster.local`. ## If your cluster has been configured with another name, you can ## specify it with the `clusterDomain` attribute. opsManager: # Alias of cloudManager configMapRef: name: my-project credentials: my-credentials persistent: true configSrvPodSpec: # if "persistence" element is omitted then Operator uses the # default size (5Gi) for mounting single Persistent Volume podTemplate: spec: affinity: podAffinity: requiredDuringSchedulingIgnoredDuringExecution: - labelSelector: matchExpressions: - key: security operator: In values: - S1 topologyKey: failure-domain.beta.kubernetes.io/zone nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/e2e-az-name operator: In values: - e2e-az1 - e2e-az2 podAntiAffinity: requiredDuringSchedulingIgnoredDuringExecution: - podAffinityTerm: topologyKey: nodeId mongosPodSpec: podTemplate: spec: affinity: podAffinity: requiredDuringSchedulingIgnoredDuringExecution: - labelSelector: matchExpressions: - key: security operator: In values: - S1 topologyKey: failure-domain.beta.kubernetes.io/zone nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/e2e-az-name operator: In values: - e2e-az1 - e2e-az2 podAntiAffinity: requiredDuringSchedulingIgnoredDuringExecution: - podAffinityTerm: topologyKey: nodeId shardPodSpec: persistence: multiple: # if the child of "multiple" is omitted then the default size will be used. # 16GB for "data", 1GB for "journal", 3GB for "logs" data: storage: "20Gi" logs: storage: "4Gi" storageClass: standard podTemplate: spec: affinity: podAffinity: requiredDuringSchedulingIgnoredDuringExecution: - labelSelector: matchExpressions: - key: security operator: In values: - S1 topologyKey: failure-domain.beta.kubernetes.io/zone nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/e2e-az-name operator: In values: - e2e-az1 - e2e-az2 podAntiAffinity: requiredDuringSchedulingIgnoredDuringExecution: - podAffinityTerm: topologyKey: nodeId mongos: additionalMongodConfig: systemLog: logAppend: true verbosity: 4 configSrv: additionalMongodConfig: operationProfiling: mode: slowOp shard: additionalMongodConfig: storage: journal: commitIntervalMs: 50 security: certsSecretPrefix: "prefix" tls: ca: custom-ca authentication: enabled: true modes: ["X509"] internalCluster: "X509" statefulSet: spec: serviceName: my-service ...
StatefulSet 设置
以下 StatefulSet 设置仅适用于副本集和分片集群资源类型。
The Kubernetes Operator supports overriding the Kubernetes Operator default StatefulSet and PVC settings by specifying values for spec.statefulSet.spec fields in the MongoDB resource specification. However, only certain fields are preserved during the merge process. The following tables list the supported override fields.
spec.statefulSet.spec类型:集合
Kubernetes Operator 的MongoDB控制器为
MongoDB资源创建的 StatefulSet 规范。
StatefulSet 覆盖字段
当在 spec.statefulSet.spec 中指定值时,以下字段将合并并优先于默认 StatefulSet 设置。字段路径与 StatefulSet 定义相对,因此 spec.replicas 对应 MongoDB 资源规格中的 spec.statefulSet.spec.replicas。
字段 |
|---|
|
|
|
|
|
|
|
|
|
spec.statefulSet.spec.serviceName类型:字符串
默认值:
<resource_name>-svc和<resource_name>-svc-external要创建或用于StatefulSet的Kubernetes服务的名称。如果具有此名称的服务已存在, MongoDB Controllers for Kubernetes Operator 不会删除或重新创建该服务。通过此设置,您可以创建自己的自定义服务,并允许Kubernetes Operator 重复使用这些服务。
PVC (VolumeClaimTemplates) 覆盖字段
Kubernetes 操作符仅当其 metadata.name 与现有卷申请模板的名称匹配时,才会合并您在 spec.statefulSet.spec.volumeClaimTemplates 中指定的卷申请模板。下表显示,当在 spec.statefulSet.spec.volumeClaimTemplates 中指定值时,Kubernetes 操作符会保留哪些 PVC 字段,删除哪些。字段路径(Field Path)相对于单个卷申请模板。因此,spec.volumeMode 对应于 MongoDB 资源规范中的 spec.statefulSet.spec.volumeClaimTemplates.spec.volumeMode。
支持(保留) | 不支持(已删除) |
|---|---|
|
|
| [1] | Kubernetes 操作符将您指定的访问模式添加到默认访问模式,而不是替换它们。 |