注意
对于此页面上提到的所有 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 部署配置以反映更改。
每个 MongoDB 资源都使用 YAML 中的对象规范来定义 MongoDB 对象的特性和设置:独立运行、副本集和分片集群。
通用的资源设置
每种资源类型都必须使用以下设置:
必需
spec.credentials类型:字符串
Required. Name of the Kubernetes secret you created as Ops Manager API authentication credentials for the Kubernetes Operator to communicate with Cloud Manager or Ops Manager.
持有凭证的 Ops Manager Kubernetes Secret 对象必须与您要创建的资源位于同一个命名空间中。
重要
Operator 管理对密钥的更改
Kubernetes Operator 会跟踪该 Secret 的任何更改并协调
MongoDB资源的状态。
spec.persistent类型:布尔值
默认:真
警告:授予容器写入持久卷的权限。 Kubernetes Operator 在 中设置
fsGroup = 2000、runAsUser = 2000和runAsNonRoot = truesecurityContext。 Kubernetes Operator 将fsgroup设置为等于runAsUser,以使在容器中运行主进程的用户可写入该卷。要学习;了解更多信息,请参阅Kubernetes文档中的为 Pod 或容器配置安全上下文以及相关讨论。如果重新部署资源无法解决持久卷的问题,联系MongoDB支持部门。If you do not use Persistent Volumes, the Disk Usage and Disk IOPS charts cannot be displayed in either the Processes tab on the Deployment page or in the Metrics page when reviewing the data for this deployment.
spec.version类型:字符串
您在此
MongoDB资源上安装的 MongoDB 版本。注意
如果您将此值更新为数据库资源的更高版本的MongoDB ,则特征兼容性版本将保留为您要升级的MongoDB版本,以便您可以在必要时选择降级。如果您希望特征兼容性版本与新的MongoDB版本匹配,则必须手动将
spec.featureCompatibilityVersion设立为新版本或设置为AlwaysMatchVersion。要学习;了解详情,请参阅spec.featureCompatibilityVersion。
可选的
每个资源必须使用以下设置之一:
spec.opsManager.configMapRef.name类型:字符串
具有Cloud Manager或Ops Manager连接配置的 ConfigMap
spec.cloudManager.configMapRef.name的名称。 设置是此设置的别名,可以用来代替它。此值必须与待创建的资源位于同一命名空间。
重要
Operator 管理对 ConfigMap 的更改
Kubernetes Operator 会跟踪该 ConfigMap 的任何更改并协调
MongoDB资源的状态。
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类型:数字
在MongoDB Agent轮换日志之前,Atlas 审核日志文件的最大大小(以 MB 为单位)。
spec.agent.mongod.auditlogRotate.numTotal类型:整型
MongoDB Ops Manager保留的Atlas 审核日志文件总数。 如果不设立此值,则Atlas 审核日志文件的总数默认为0 。
spec.agent.mongod.auditlogRotate.percentOfDiskspace类型:数字
Ops Manager 可用于存储日志文件的总磁盘空间的最大百分比,以十进制表示。如果超过此限制,Ops Manager 将删除压缩的日志文件,直到达到此限制。Ops Manager 首先删除最早的日志文件。
默认值为0.02 。
spec.agent.mongod.logRotate.sizeThresholdMB类型:整型
Ops Manager轮换单个日志文件之前,该文件的最大大小(以 MB 为单位)。如果Ops Manager达到此
sizeThresholdMB或spec.agent.mongod.logRotate.timeThresholdHrs中给定的值,则立即轮换日志文件。
spec.agent.mongod.logRotate.timeThresholdHrs类型:整型
下次轮换之前单个日志文件的最大持续时间(以小时为单位)。 自上次轮换以来的时间。
一旦文件满足此
timeThresholdHrsspec.agent.mongod.logRotate.sizeThresholdMB或 , Ops Manager就会轮换日志文件。
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。setFeatureCompatibilityVersion要学习;了解有关功能兼容性的更多信息,请参阅MongoDB手册中的 。
spec.clusterDomain类型:字符串
默认值:cluster.local
部署 Kubernetes Operator 的 Kubernetes 集群的域名。当 Kubernetes 创建 StatefulSet 时,Kubernetes 会为每个 Pod 分配一个 FQDN。要更新 Cloud Manager 或 Ops Manager,Kubernetes Operator 使用提供的集群名称计算每个 Pod 的 FQDN。Kubernetes 不提供这些主机名查询用的 API。
警告
spec.clusterDomain如果Kubernetes集群具有默认 以外的默认域,则必须设立cluster.local。如果既不使用默认,也不设立 选项, Kubernetes Operatorspec.clusterDomain可能无法按预期运行。
spec.clusterName类型:字符串
默认值:cluster.local
部署 Kubernetes Operator 的 Kubernetes 集群的域名。当 Kubernetes 创建 StatefulSet 时,Kubernetes 会为每个 Pod 分配一个 FQDN。要更新 Cloud Manager 或 Ops Manager,Kubernetes Operator 使用提供的集群名称计算每个 Pod 的 FQDN。Kubernetes 不提供这些主机名查询用的 API。
警告
spec.clusterDomain如果Kubernetes集群具有默认 以外的默认域,则必须设立cluster.local。如果既不使用默认,也不设立 选项, Kubernetes Operatorspec.clusterDomain可能无法按预期运行。
metadata.namespace类型:字符串
Kubernetes namespace where you create this
MongoDBresource and other objects.
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 部署项:
独立的设置
注意
所有独立设置也会应用于副本集资源。
spec.additionalMongodConfig类型:集合
启动 MongoDB 进程时需要使用的其他配置选项。
Kubernetes Operator 支持您通过 MongoDB 助手部署的 MongoDB 版本所支持的所有配置选项,但 Kubernetes Operator 会覆盖您为以下任何选项提供的值:
要详细了解 Kubernetes Operator 拥有的配置选项,请参阅 MongoDB Kubernetes Operator 独有设置。
如需了解可以使用哪些配置选项,请参阅 Ops Manager 文档中的“MongoDB 部署高级选项”。
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>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类型:集合
覆盖
spec.externalAccess中默认值的规范。When you set the
spec.externalAccesssetting, the Kubernetes Operator automatically creates an external load balancer service with default values. You can override certain values or add new values depending on your needs. For example, if you intend to create NodePort services and don't need a load balancer, you must configure overrides in your Kubernetes specification: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类型:集合
Key-value pairs that let you add cloud provider-specific configuration settings to all clusters in your deployment. To learn more, see annotations and the documentation for your Kubernetes cloud provider.
您可以使用注解为Kubernetes Operator 部署使用的外部服务指定占位符值。Kubernetes Operator 会自动将这些值替换为正确的值,如下表所述。使用占位符,您可以在每个服务中为特定 Pod 提供特定注释。
值说明{resourceName}{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.进程主机名取决于您的部署配置。如果已将部署配置为使用
external domains,则进程主机名将使用以下格式:{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 创建持久化卷声明,并将数据、事务日志与运行日志的所有三个目录挂载到同一个持久卷。
注意
如果
spec.persistent: true,则必须设立此集合中的值。您可以设置此集合或
persistence.multiple集合,但不能同时设置两者。
标量数据类型说明labelSelector字符串
用于将已安装卷绑定到目录的标签。
storage字符串
storageClass字符串
持久卷声明中指定的存储类型。您可以将此存储类型创建为 StorageClass 对象,然后再在此对象规范中使用。
确保将 StorageClass 设立为
reclaimPolicyRetain。这可确保在删除持久卷声明时保留数据。
spec.podSpec.persistence.multiple.data类型:集合
让 Kubernetes Operator 创建持久卷声明,并将数据目录挂载到自己的持久卷上。
注意
如果
spec.persistent: true,则必须设立此集合中的值。您可以设置此集合或
persistence.single集合,但不能同时设置这两个集合。
标量数据类型说明labelSelector字符串
用于将已安装卷绑定到目录的标签。
storage字符串
storageClass字符串
独立部署所需的存储类型。您可以将此存储类型创建为 StorageClass 对象,然后再在此对象规范中使用。
确保将 StorageClass 设立为
reclaimPolicyRetain。这可确保在删除持久卷声明时保留数据。
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 对象,然后再在此对象规范中使用。
Make sure to set the StorageClass
reclaimPolicyto Retain. This ensures that data is retained when a Persistent Volume Claim is removed.
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 对象,然后再在此对象规范中使用。
Make sure to set the StorageClass
reclaimPolicyto Retain. This ensures that data is retained when a Persistent Volume Claim is removed.
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 的元数据。
To review which fields you can add to
spec.podSpec.podTemplate.metadata, see the Kubernetes documentation.
spec.podSpec.podTemplate.spec类型:集合
Kubernetes Operator 的MongoDB控制器为MongoDB 数据库资源创建的Kubernetes Pod 的规范。
要查看哪些字段可以添加到
spec.podSpec.podTemplate.spec,请参阅Kubernetes PodSpec v1 核心API。注意
在将容器添加到
spec.podSpec.podTemplate.spec.containers时,Kubernetes Operator 将它们添加到 Kubernetes Pod 中。这些容器附加到 pod 中的 MongoDB 数据库资源容器。使用此设置为每个 Pod 指定 CPU 和 RAM 分配。 相关示例请参阅 GitHub 上的示例。
spec.podSpec.podTemplate.spec.affinity.nodeAffinity类型:结构
Kubernetes rule to place Pods for replica set on a specific range of nodes.
为了优化读写性能,请使用节点关联性规则来限制 Pod 在特定 节点 上运行 ,或者更愿意在特定 节点 上运行 。
spec.podSpec.podTemplate.spec.affinity.podAffinity类型:结构
Kubernetes规则来确定多个
MongoDB资源Pod 是否必须与其他 Pod 共处一地。要学习;了解有关使用案例的更多信息,请参阅Kubernetes文档中的关联和反关联。
spec.podSpec.podTemplate.spec.affinity.podAntiAffinity类型:结构
Default: kubernetes.io/hostname
设置规则以将托管
MongoDB资源的Pod 分布到不同位置。位置可以是单个节点、机架或地区。默认下, Kubernetes Operator 会尝试将 Pod 分布到不同的节点。
spec.podSpec.podTemplate.spec.affinity.podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution.topologyKey类型:结构
Default: kubernetes.io/hostname
该键定义了哪个 标签 用于确定属于哪个拓扑 域 节点属于。
副本集设置
注意
所有独立设置也会应用于副本集资源。
以下设置适用于副本集资源类型:
spec.backup类型:集合
spec.backup.mode的集合容器,可实现Kubernetes Operator 中MongoDB资源的连续备份。
spec.backup.assignmentLabels类型:数组
以逗号分隔的标签列表,用于将备份程序、 oplog存储、块存储、S3快照存储和文件系统存储分配给特定的项目或群组。使用分配标签来标识特定备份存储与特定项目的关联。
如果您使用 Kubernetes Operator 设置分配标签,您在 Kubernetes 配置文件中为分配标签设置的值将覆盖 Ops Manager 用户界面中定义的值。您未使用 Kubernetes Operator 设置的分配标签继续使用 Ops Manager 用户界面中设置的值。
注意
如果设立此参数,则与 值链接的API密钥必须具有
spec.credentialsGlobal Owner角色。
spec.backup.mode类型:字符串
为 MongoDB 资源启用连续备份。可能的值为
enabled、disabled和terminated。注意
spec.backup.mode设置依赖于Ops Manager中启用的备份,并要求将Ops Manager资源规范中的spec.backup.enabled值设立为true。使用 为MongoDB资源启用连续备份后,您可以检查备份状态。
spec.backup.mode
spec.backup.encryption.kmip类型:对象
包含 KMIP 备份加密配置设置的对象。要了解更多信息,请参阅为 Ops Manager 配置 KMIP 备份加密。
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类型:数字
使用 24 小时时钟安排快照的一天中的 UTC 小时。您可以设立介于
0和23(含)之间的值。
spec.backup.snapshotSchedule.referenceMinuteOfHour类型:数字
UTC minute of the hour to schedule snapshots. You can set a value between
0and59, inclusive.
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。
警告
You must set
spec.clusterDomainif your Kubernetes cluster has a default domain other than the defaultcluster.local. If you neither use the default nor set thespec.clusterDomainoption, the Kubernetes Operator might not function as expected.
spec.connectivity.replicaSetHorizons类型:集合
允许您为客户端应用程序和 MongoDB 助手提供不同的 DNS 设置。Kubernetes Operator 为副本集节点使用水平分割 DNS。此功能允许 Kubernetes 集群内部与 Kubernetes 外部进行通信。
您可以为每台主机添加多个外部映射。
水平分割要求:
确保该数组中的每个值是唯一的。
确保此大量中的条目数与
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.
例子
在此示例中,副本集成员在
example-localhost配置上相互通信。 客户端使用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类型:字符串
用于向外部公开您的副本集部署的外部域。
By default, each replica set member uses the Kubernetes Pod's FQDN (
*.svc.cluster.local) as the default hostname. However, if you add an external domain to this setting, the replica set uses a hostname that is a subdomain of the specified domain instead. This hostname uses the following format:<replica-set-name>-<pod-idx>.<externalDomain>例如:
replica-set-1.example.com使用此设置部署副本集后, Kubernetes Operator
processes[n].hostname使用带有外部域的主机名来覆盖Ops Manager自动化配置中的 字段。然后, MongoDB 助手会使用此主机名连接到mongod。要指定用于连接到副本集的其他主机名,可以使用
spec.connectivity.replicaSetHorizons设置。但是,以下连接仍使用带有外部域的主机名:要连接到 的MongoDB
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类型:字符串
表示副本集节点成为主节点的相对可能性的数字。
要增加副本集节点成为主节点的相对可能性,请指定较高的
priority值。要降低副本集节点成为主节点的相对可能性,请指定较低的
priority值。
例如,
memberConfig.priority为1.5的成员比memberConfig.priority为0.5的成员更有可能成为主节点。memberConfig.priority为0的节点没有资格成为主节点。要了解更多信息,请参阅节点优先级。
spec.memberConfig.tags类型:地图
副本集标签映射,用于将读取和写入操作定向到您的 MongoDB 副本集的特定节点。
以下设置仅适用于副本集资源类型:
spec.backup.autoTerminateOnDeletion类型:布尔值
用于控制在您删除MongoDB资源时Kubernetes Operator 是否停止并终止备份的标志。如果省略,默认值为
false。当您想要在true设立为spec.backup.mode时删除MongoDB自定义资源时,将此标志设置为enabled非常有用。
分片集群设置
注意
除非另行说明,否则所有副本集设置也适用于分片集群资源。
以下设置仅适用于分片集群资源类型:
spec.backup.snapshotSchedule.clusterCheckpointIntervalMin类型:数字
连续集群检查点之间的分钟数。 此设置仅适用于运行分片的且特征兼容性版本为4.0或更早版本的分MongoDB集群。 此数字决定了分片集群的时间点恢复分片的。 您可以设立值设置为
15、30或60。
spec.configServerCount类型:整型
必需。配置服务器中的成员数。
spec.configSrv.additionalMongodConfig类型:集合
Kubernetes Operator 支持您通过 MongoDB 助手部署的 MongoDB 版本所支持的所有配置选项,但 Kubernetes Operator 会覆盖您为以下任何选项提供的值:
要详细了解 Kubernetes Operator 拥有的配置选项,请参阅 MongoDB Kubernetes Operator 独有设置。
如需了解可以使用哪些配置选项,请参阅 Ops Manager 文档中的“MongoDB 部署高级选项”。
spec.configSrv.agent类型:集合
每个配置服务器成员的 MongoDB 助手配置设置。
spec.configSrv.agent.startupOptions类型:集合
要用来启动每个配置服务器成员的 MongoDB 助手设置。
您必须以键值对形式提供 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字符串
storageClass字符串
持久卷声明中指定的存储类型。您可以将此存储类型创建为 StorageClass 对象,然后再在此对象规范中使用。
Make sure to set the StorageClass
reclaimPolicyto Retain. This ensures that data is retained when a Persistent Volume Claim is removed.
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 对象,然后再在此对象规范中使用。
Make sure to set the StorageClass
reclaimPolicyto Retain. This ensures that data is retained when a Persistent Volume Claim is removed.
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 对象,然后再在此对象规范中使用。
Make sure to set the StorageClass
reclaimPolicyto Retain. This ensures that data is retained when a Persistent Volume Claim is removed.
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 对象,然后再在此对象规范中使用。
Make sure to set the StorageClass
reclaimPolicyto Retain. This ensures that data is retained when a Persistent Volume Claim is removed.
spec.configSrvPodSpec.podTemplate类型:集合
Template for the Kubernetes Pods that the MongoDB Controllers for Kubernetes Operator creates for each config server member.
模板值优先于
spec.configSrvPodSpec中指定的值。注意
Kubernetes Operator 不会验证您在
spec.configSrvPodSpec.podTemplate中提供的字段。
spec.configSrvPodSpec.podTemplate.metadata类型:集合
MongoDB Controllers for Kubernetes Operator 为每个配置服务器成员创建的Kubernetes Pod 的元数据。
To review which fields you can add to
spec.configSrvPodSpec.podTemplate.metadata, see the Kubernetes documentation.
spec.configSrvPodSpec.podTemplate.spec类型:集合
Kubernetes Operator 的MongoDB控制器为每个配置服务器成员创建的Kubernetes Pod 的规范。
To review which fields you can add to
spec.configSrvPodSpec.podTemplate.spec, see the 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 rule to place Pods for replica set on a specific range of nodes.
为了优化读写性能,请使用节点关联性规则来限制 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类型:整型
必需。每个分片的成员数。
spec.mongosCount类型:整型
Required. Number of
mongosinstances in the sharded cluster.
spec.mongos.additionalMongodConfig类型:集合
Kubernetes Operator 支持您通过 MongoDB 助手部署的 MongoDB 版本所支持的所有配置选项,但 Kubernetes Operator 会覆盖您为以下任何选项提供的值:
要详细了解 Kubernetes Operator 拥有的配置选项,请参阅 MongoDB Kubernetes Operator 独有设置。
如需了解可以使用哪些配置选项,请参阅 Ops Manager 文档中的“MongoDB 部署高级选项”。
spec.mongos.agent类型:集合
每个 实例的MongoDB
mongos助手配置设置。
spec.mongos.agent.startupOptions类型:集合
要用于启动每个 实例的MongoDB
mongos助手设置。您必须以键值对形式提供 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类型:集合
Kubernetes Operator 的MongoDB控制器为每个 实例创建的Kubernetes Pod
mongos的模板。模板值优先于
spec.mongosPodSpec中指定的值。注意
Kubernetes Operator 不会验证您在
spec.mongosPodSpec.podTemplate中提供的字段。
spec.mongosPodSpec.podTemplate.metadata类型:集合
Kubernetes Operator 的MongoDB控制器为每个 实例创建的Kubernetes Pod
mongos的元数据。To review which fields you can add to
spec.mongosPodSpec.podTemplate.metadata, see the Kubernetes documentation.
spec.mongosPodSpec.podTemplate.spec类型:集合
Specifications of the Kubernetes Pods that the MongoDB Controllers for Kubernetes Operator creates for each
mongosinstance.To review which fields you can add to
spec.mongosPodSpec.podTemplate.spec, see the Kubernetes PodSpec v1 core API.注意
当您将容器添加到
spec.mongosPodSpec.podTemplate.spec.containers时, Kubernetes Operator 会将它们添加到Kubernetes Pod 中。这些容器附加到mongosPod 中的每个 实例容器。使用此设置为每个 Pod 指定 CPU 和 RAM 分配。 相关示例请参阅 GitHub 上的示例。
spec.mongosPodSpec.podTemplate.spec.affinity.podAffinity类型:集合
Optional. Kubernetes rule to determine if multiple
MongoDBresource Pods must be co-located with other Pods.
spec.mongosPodSpec.podTemplate.spec.affinity.nodeAffinity类型:集合
Kubernetes rule to place Pods for replica set on a specific range of nodes.
为了优化读写性能,请使用节点关联性规则来限制 Pod 在特定 节点 上运行 ,或者更愿意在特定 节点 上运行 。
spec.mongosPodSpec.podTemplate.spec.affinity.podAntiAffinity类型:字符串
Default: kubernetes.io/hostname
Sets a rule to spread Pods hosting
MongoDBresource to different locations. A location can be a single node, rack, or region. By default, Kubernetes Operator tries to spread pods across different nodes.
spec.mongosPodSpec.podTemplate.spec.affinity.podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution.topologyKey类型:字符串
Default: kubernetes.io/hostname
该键定义了哪个 标签 用于确定属于哪个拓扑 域 节点属于。
spec.shardCount类型:整型
必需。分片集群中的分片数。
spec.shard.additionalMongodConfig类型:集合
Kubernetes Operator 支持您通过 MongoDB 助手部署的 MongoDB 版本所支持的所有配置选项,但 Kubernetes Operator 会覆盖您为以下任何选项提供的值:
要详细了解 Kubernetes Operator 拥有的配置选项,请参阅 MongoDB Kubernetes Operator 独有设置。
如需了解可以使用哪些配置选项,请参阅 Ops Manager 文档中的“MongoDB 部署高级选项”。
spec.shard.agent类型:集合
每个分片集群分片成员的 MongoDB 助手配置设置。
spec.shard.agent.startupOptions类型:集合
您希望用来启动每个分片集群分片成员的 MongoDB 助手设置。
您必须以键值对形式提供 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 对象,然后再在此对象规范中使用。
Make sure to set the StorageClass
reclaimPolicyto Retain. This ensures that data is retained when a Persistent Volume Claim is removed.
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 对象,然后再在此对象规范中使用。
Make sure to set the StorageClass
reclaimPolicyto Retain. This ensures that data is retained when a Persistent Volume Claim is removed.
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 对象,然后再在此对象规范中使用。
Make sure to set the StorageClass
reclaimPolicyto Retain. This ensures that data is retained when a Persistent Volume Claim is removed.
spec.shardPodSpec.podTemplate类型:集合
Template for the Kubernetes Pods that the MongoDB Controllers for Kubernetes Operator creates for each sharded cluster shard member.
模板值优先于
spec.shardPodSpec中指定的值。注意
Kubernetes Operator 不会验证您在
spec.shardPodSpec.podTemplate中提供的字段。
spec.shardPodSpec.podTemplate.metadata类型:集合
Kubernetes Operator 的MongoDB控制器为每个分片集群分片成员创建的Kubernetes Pod 的元数据。
To review which fields you can add to
spec.shardPodSpec.podTemplate.metadata, see the Kubernetes documentation.
spec.shardPodSpec.podTemplate.spec类型:集合
Kubernetes Operator 的MongoDB控制器为每个分片集群分片成员创建的Kubernetes Pod 的规范。
To review which fields you can add to
spec.shardPodSpec.podTemplate.spec, see the Kubernetes PodSpec v1 core API.注意
在您将容器添加到
spec.shardPodSpec.podTemplate.spec.containers时,Kubernetes Operator 将它们添加到 Kubernetes Pod 中。这些容器会附加到 Pod 中的每个分片集群分片成员容器。使用此设置为每个 Pod 指定 CPU 和 RAM 分配。 相关示例请参阅 GitHub 上的示例。
spec.shardPodSpec.podTemplate.spec.affinity.podAffinity类型:字符串
Kubernetes rule to determine whether multiple
MongoDBresource Pods must be co-located with other Pods. To learn more about the use cases, see Affinity and Anti-Affinity in the Kubernetes documentation.
spec.shardPodSpec.podTemplate.spec.affinity.nodeAffinity类型:字符串
Kubernetes rule to place Pods for replica set on a specific range of nodes.
为了优化读写性能,请使用节点关联性规则来限制 Pod 在特定 节点 上运行 ,或者更愿意在特定 节点 上运行 。
spec.shardPodSpec.podTemplate.spec.affinity.podAntiAffinity类型:字符串
Default: kubernetes.io/hostname
Sets a rule to spread Pods hosting
MongoDBresource to different locations. A location can be a single node, rack, or region. By default, Kubernetes Operator tries to spread pods across different nodes.
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 的元数据。
To review which fields you can add to
spec.shardSpecificPodSpec.podTemplate.metadata, see the Kubernetes documentation.
spec.shardSpecificPodSpec.podTemplate.spec类型:集合
Kubernetes Operator 的MongoDB控制器为特定分片创建的Kubernetes Pod 的规范。
To review which fields you can add to
spec.shardSpecificPodSpec.podTemplate.spec, see the 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 rule to determine whether multiple
MongoDBresource Pods must be co-located with other Pods. To learn more about the use cases, see Affinity and Anti-Affinity in the Kubernetes documentation.
spec.shardSpecificPodSpec.podTemplate.spec.affinity.podAntiAffinity类型:字符串
Default: kubernetes.io/hostname
Sets a rule to spread Pods hosting
MongoDBresource to different locations. A location can be a single node, rack, or region. By default, Kubernetes Operator tries to spread pods across different nodes.
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>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类型:集合
仅在传递给
spec.configSrv.clusterSpecList和spec.shard.clusterSpecList的clusterSpecItem对象中可用。 覆盖给定集群的现有持久性配置。
statefulSet类型:集合
为多 Kubernetes集群MongoDB 部署中集群的每个 StatefulSet 提供 StatefulSet 覆盖的配置。要设立适用于多 Kubernetes集群MongoDB 部署中所有集群的全局配置,请参阅 spec.statefulSet.spec.
此设置仅适用于多 Kubernetes 集群 MongoDB 部署中的副本集资源类型。
spec.duplicateServiceObjects注意
此字段专门用于多集群分片集群部署。
类型:布尔值
Optional
默认值:
true如果拓扑结构不是
MultiCluster,则忽略。 适用于所有分片集群组件的服务:mongos、configSrv和shards。- 如果设立为
true: - Kubernetes Operator 从每个成员集群的所有成员集群中创建所有
Pod Services。 - 如果设立为
false: - Kubernetes Operator 仅创建
- 如果设立为
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.publishNotReadyAddresstrueSpecifies that DNS records are created even if the Pod isn't ready. Do not set to
falsefor any database Pod.注意
如果设立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.publishNotReadyAddresstrueSpecifies that DNS records are created even if the Pod isn't ready. Do not set to
falsefor any database Pod.注意
如果设立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类型:集合
仅在传递给
spec.configSrv.clusterSpecList和spec.shard.clusterSpecList的clusterSpecItem对象中可用。 覆盖给定集群的现有持久性配置。
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字符串
storageClass字符串
持久卷声明中指定的存储类型。您可以将此存储类型创建为 StorageClass 对象,然后再在此对象规范中使用。
Make sure to set the StorageClass
reclaimPolicyto Retain. This ensures that data is retained when a Persistent Volume Claim is removed.
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类型:对象
Optional
Object that contains the details of the secret for TLS authentication.
spec.prometheus.tlseSecretKeyRef.key类型:字符串
Optional
默认值:
"password"Human-readable string that indentifies the key in the secret that stores the password for TLS authentication. If you don't specify this setting, the default applies.
spec.prometheus.tlseSecretKeyRef.name类型:字符串
可选的
Human-readable label that identifies the secret that contains the password for TLS authentication. If you want to use Prometheus with your MongoDB resource and you want to use TLS authentication, you must specify this setting.
安全设置
以下安全设置仅适用于副本集和分片集群资源类型:
spec.security.tls.ca类型:字符串
Provide the name of the ConfigMap that stores the CA for the
MongoDBresource.重要
If you use a custom CA to sign your TLS certificates for the
MongoDBresource, you must specify this parameter.Kubernetes Operator 要求您在 ConfigMap 中将
MongoDB资源证书命名为ca-pem。
spec.security.certsSecretPrefix类型:字符串
要作为前缀添加到您创建的 Kubernetes 密钥中的文本,这些密钥包含了副本集或分片集群的 TLS 密钥和证书。
您必须在密钥前面加上
<prefix>-<metadata.name>作为前缀。For example, if you call your deployment
my-deploymentand you set the prefix tomdb, you must name the TLS secret for the client TLS communicationsmdb-my-deployment-cert. Also, you must name the TLS secret for internal cluster authentication (if enabled)mdb-my-deployment-clusterfile.要了解有关命名包含 TLS 证书的密钥的更多信息,请参阅部署副本集中适用于您的部署的主题。
spec.security.tls.additionalCertificateDomains类型:布尔值
List of every domain that should be added to TLS certificates to each pod in this deployment. When you set this parameter, every CSR that the Kubernetes Operator transforms into a TLS certificate includes a SAN in the form
<pod name>.<additional cert domain>.副本设立资源不需要此参数。请改用
spec.connectivity.replicaSetHorizons。注意
If you add this parameter to a TLS-enabled resource, Kubernetes displays an error when the resource reaches the
Pendingstate. This error displays:Please manually remove the |csr| in order to proceed.To remedy this issue:删除任何现有的 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类型:布尔值
默认值:
false指定是否在Cloud Manager或Ops Manager项目上启用身份验证。如果设立为
true,则必须在spec.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 内部集群身份验证
要为Cloud Manager或Ops Manager项目启用X.509 内部集群身份验证,请将此值设立为
["X509"]并指定以下设置:为
spec.security.certsSecretPrefix设置提供一个值。
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类型:字符串
指定是否启用 X.509 内部集群身份验证。
要启用 X.509 内部集群身份验证,请设置为
"X509"。要求指定以下设置:spec.security.authentication.modes: ["X509"]
Kubernetes Operator 接受以下值:
["X509"]:启用 X.509 内部集群身份验证。""或省略:未启用内部集群身份验证。
重要
启用内部集群身份验证后,就无法再将其禁用。
spec.security.authentication.requireClientTLSAuthentication类型:布尔值
默认值:
falseSpecifies whether the MongoDB host requires clients to connect using a TLS certificate. Defaults to
trueif you enable TLS authentication.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 身份验证所需。
LDAP 服务器的主机名和端口列表。按以下格式指定主机名及其相应的端口:
spec: security: authentication: ldap: servers: - "<hostname1>:<port1>" - "<hostname2>:<port2>"
spec.security.authentication.ldap.transportSecurity类型:字符串
LDAP 身份验证所需。
指定 LDAP 服务器是否接受 TLS。
If the LDAP server accepts TLS, set the value to
tls. If the LDAP server doesn't accept TLS, leave this value blank or set the value tonone.注意
如果指定
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 服务器时绑定的密码。
spec.security.authentication.ldap.authzQueryTemplate类型:字符串
是 LDAP 授权所必需的。
由MongoDB执行的 RFC4515 和
spec.security.authentication.ldap.serversRFC4516 LDAP格式查询URL模板,用于获取用户所属的LDAP群组。该查询相对于 中指定的一个或多个托管。您可以在模板中使用以下词元:{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).提示
MongoDB 手册中的 security.ldap.userToDNMapping
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类型:字符串
必需
有效值为
WorkforceIdentityFederation和WorkloadIdentityFederation。使用 Workforce Identity Federation 配置单点登录,以便人类用户访问权限部署。要以编程方式访问权限部署的应用程序,请使用 Workload Identity Federation。每个MongoDB资源只能配置一个 Workforce Identity Federation IdP。要学习;了解详情,请参阅使用 OIDC/OAuth2 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类型:字符串
MongoDB 部署的MongoDB助手使用的身份验证机制。有效值为
SCRAM、SCRAM-SHA-1、MONGODB-CR、X509、OIDC和LDAP。您指定的值也必须存在于spec.security.authentication.modes中。我们建议使用SCRAM-SHA-256SCRAM() 而不是SCRAM-SHA-1。如果指定SCRAM-SHA-1,则还必须指定MONGODB-CR。This setting is required if you specified more than one value for
spec.security.authentication.modes.
spec.security.authentication.agents.automationUserName类型:字符串
MongoDB助手与MongoDB 部署交互时使用的用户名。用户名根据 映射到LDAP标识名 (DN)。生成的 DN
spec.security.authentication.ldap.userToDNMapping必须已存在于LDAP部署中。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类型:字符串
包含 用户密码的密钥名称。您必须在部署Kubernetes Operator
spec.security.authentication.agents.automationUserName的同一命名空间中创建此密钥:kubectl create secret generic ldap-agent-user \ --from-literal="password=<password>" -n <metadata.namespace> spec.security.authentication.agents.automationUserName此密钥必须包含一个密钥,其值与LDAP部署中的 用户的密码匹配。This setting is required if
spec.security.authentication.agents.modeisLDAP.
spec.security.authentication.agents.automationPasswordSecretRef.key类型:字符串
键入包含
spec.security.authentication.agents.automationPasswordSecretRef.name中用户密码的spec.security.authentication.agents.automationUserName密钥。This setting is required if
spec.security.authentication.agents.modeisLDAP.
spec.security.authentication.agents.clientCertificateSecretRef.name类型:字符串
Specifies the secret that contains the MongoDB Agent's TLS certificate. If omitted, defaults to
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类型:数组
定义分配此
spec.security.roles.role的用户可以连接的IP解决的数组。
spec.security.roles.authenticationRestrictions.clientSource类型:数组
分配此 的用户可以从中进行连接的IP地址或 CIDR
spec.security.roles.role块的数组。如果请求来自此数组中不存在的客户端,则 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类型:数组
被授予此角色的用户可以执行的动作列表。有关接受值的列表,请参阅《MongoDB 手册》中的特权动作,了解利用 Kubernetes Operator 可以部署的 MongoDB 版本。
spec.security.roles.privileges.resource类型:集合
权限
actions应用的资源。此集合必须包含以下任一项:
spec.security.roles.privileges.resource.cluster值为true的 设置。
spec.security.roles.privileges.resource.database类型:字符串
应用权限
actions的数据库。如果您为此设置提供值,则还必须为
spec.security.roles.privileges.resource.collection提供值。
spec.security.roles.privileges.resource.collection类型:字符串
如果您为此设置提供值,则还必须为
spec.security.roles.privileges.resource.database提供值。
spec.security.roles.privileges.resource.cluster类型:布尔值
默认值:False
actions指示权限 应用于MongoDB 部署中的所有数据库和集合的标志。如果省略,则默认为false。如果设立为 true,则不要为
spec.security.roles.privileges.resource.database和spec.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.
StatefulSet 覆盖字段
当您在 中指定值时,以下字段将合并并优先于默认StatefulSetspec.statefulSet.spec 设置。字段路径相对于 StatefulSet 定义,因此spec.replicas spec.statefulSet.spec.replicas对应于MongoDB资源规范中的 。
字段 |
|---|
|
|
|
|
|
|
|
|
|
spec.statefulSet.spec.serviceName类型:字符串
默认值:
<resource_name>-svc和<resource_name>-svc-external要创建或用于StatefulSet的Kubernetes服务的名称。如果具有此名称的服务已存在, MongoDB Controllers for Kubernetes Operator 不会删除或重新创建该服务。通过此设置,您可以创建自己的自定义服务,并允许Kubernetes Operator 重复使用这些服务。
PVC (VolumeClaimTemplates) 覆盖字段
The Kubernetes Operator merges a volume claim template that you specify in spec.statefulSet.spec.volumeClaimTemplates only if its metadata.name matches the name of an existing volume claim template. The following table shows which PVC fields the Kubernetes Operator preserves and which it drops when you specify values in spec.statefulSet.spec.volumeClaimTemplates. Field paths are relative to an individual volume claim template, so spec.volumeMode corresponds to spec.statefulSet.spec.volumeClaimTemplates.spec.volumeMode in the MongoDB resource specification.
支持(保留) | 不支持(已删除) |
|---|---|
|
|
| [1] | Kubernetes 操作符将您指定的访问模式添加到默认访问模式,而不是替换它们。 |