Navigation
This version of the documentation is archived and no longer supported. To learn how to upgrade your version of MongoDB Kubernetes Operator, refer to the upgrade documentation.

MongoDB Kubernetes Object Specification

Supported with Cloud Manager and Ops Manager 4.0

You can use Kubernetes Operator to deploy MongoDB instances with Ops Manager version 4.0 or later and Cloud Manager. At any place in this guide that says Ops Manager, you can substitute Cloud Manager.

The MongoDB Enterprise Kubernetes Operator creates Kubernetes StatefulSets from specification files that you wrote.

MongoDB resources are created in Kubernetes as custom resources. After you create or update a MongoDB resource specification, you direct MongoDB Enterprise Kubernetes Operator to apply this specification to your Kubernetes environment. Kubernetes Operator creates the defined StatefulSets, services and other Kubernetes resources. After the Operator finishes creating those objects, it updates Ops Manager deployment configuration to reflect changes.

Deployment Type StatefulSets Size of StatefulSet
Standalone 1 1 per member
Replica Set 1 1 per member
Sharded Cluster 1 1 per shard or config server member

Each object uses an object specification in YAML to define the characteristics and settings of the MongoDB object: standalone, replica set, and sharded cluster.

Common Resource Settings

Every resource type must use the following settings:

Required

apiVersion

Type: string

Required. Version of the MongoDB Kubernetes resource schema.

kind

Type: string

Required. Kind of MongoDB Kubernetes resource to create. Set this to MongoDB

metadata.name

Type: string

Required. Name of the MongoDB Kubernetes resource you are creating.

metadata.namespace

Type: string

Required. Kubernetes namespace where this MongoDB Kubernetes resource and other objects are created.

spec.credentials

Type: string

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.

Value must use namespace and name of Secret

This value must match the value you provided for namespace and name for your Ops Manager Kubernetes Secret.

Operator manages changes to the Secret

The Kubernetes Operator tracks any changes to the Secret and reconciles the state of the MongoDB Kubernetes resource.

spec.persistent

Type: boolean

Default: True

Warning

Your containers must have permissions to write to your Persistent Volume. The Kubernetes Operator sets fsGroup = 2000 in securityContext This makes Kubernetes try to fix write permissions for the Persistent Volume. If redeploying the deployment item does not fix issues with your Persistent Volumes, contact MongoDB Support.

Note

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.type

Type: string

Required. Type of MongoDB Kubernetes resource to create. Accepted values are:

  • Standalone
  • ReplicaSet
  • ShardedCluster
spec.version

Type: number

Required. Version of MongoDB that is installed on this MongoDB Kubernetes resource.

Note

If you update this value to a later version, consider setting spec.featureCompatibilityVersion to give yourself the option to downgrade if necessary.

Conditional

Every resource must use one of the following settings:

spec.opsManager.configMapRef.name

Type: string

Name of the ConfigMap with the Cloud Manager or Ops Manager connection configuration. The spec.cloudManager.configMapRef.name setting is an alias for this setting and can be used in its place.

Value must match namespace and name of ConfigMap

This value must match the value you provided for metadata.name in your Cloud Manager or Ops Manager project ConfigMap.

Operator manages changes to the ConfigMap

The Kubernetes Operator tracks any changes to the ConfigMap and reconciles the state of the MongoDB Kubernetes resource.

(Changed in version 1.3):

In prior versions of the MongoDB Enterprise Kubernetes Operator, this setting was spec.project. See the v1.2 documentation for information on the previous setting name.

spec.cloudManager.configMapRef.name

Type: string

Alias for spec.opsManager.configMapRef.name.

Optional

Every resource type may use the following settings:

spec.featureCompatibilityVersion

Type: number

Optional. Limits changes to data that occur with an upgrade to a new major version. This allows you to downgrade to the previous major version. To learn more about feature compatibility, see setFeatureCompatibilityVersion in the MongoDB Manual.

spec.clusterName

Type: string

Default: cluster.local

Domain name of the Kubernetes cluster where you deploy the Operator. When Kubernetes creates a StatefulSet, the Kubernetes assigns each pod a FQDN. To update Cloud Manager or Ops Manager, the Kubernetes Operator calculates the FQDN for each pod using a provided cluster name. Kubernetes doesn’t provide an API to query these hostnames.

Warning

You must set spec.clusterName if your Kubernetes cluster has a default domain different from default cluster.local. If you neither use the default nor set this option, the Kubernetes Operator may not function as expected.

spec.service

Type: string

Default: <resource_name>+”-svc” and <resource_name>+”-svc-external”

Name of Kubernetes service to be created or used for a StatefulSet. If the service with this name already exists, the MongoDB Enterprise Kubernetes Operator does not delete or recreate it. This setting lets users to create their custom services and lets the Operator reuse them.

spec.logLevel

Type: string

Default: INFO

Configures the level of Automation Agent logging inside the pod. Accepted values include:

  • DEBUG
  • INFO
  • WARN
  • ERROR
  • FATAL

Deployment-Specific Resource Settings

Other settings you can and must use in a MongoDB Kubernetes resource specification depend upon which MongoDB deployment item you want to create:

Standalone Settings

spec.exposedExternally

Type: boolean

Default: false

Determines whether the MongoDB deployment is exposed outside of the Kubernetes cluster. This results in Kubernetes creating a NodePort service.

spec.podSpec.cpu

Type: string

Maximum CPU capacity that must be available on a Kubernetes node to host this standalone database MongoDB Kubernetes resource.

This value maps to the limits field for CPU for the created pod.

spec.podSpec.cpuRequests

Type: string

Minimum CPU capacity for the node being created to host this standalone database MongoDB Kubernetes resource. If omitted, this value is set to spec.podSpec.cpu.

This value maps to the requests field for CPU for the created pod.

The requested value must be less than or equal to spec.podSpec.cpu.

Note

For production deployments, MongoDB recommends setting this value to 2. This value is consistent with considerations stated for MongoDB hosts.

spec.podSpec.memory

Type: string

Maximum memory capacity that must be available on a Kubernetes node to host this MongoDB Kubernetes resource on Kubernetes. This value is expressed as an integer followed by a unit of memory in JEDEC notation.

Example

If this MongoDB Kubernetes resource requires 4 gigabytes of memory, set this value to 4G.

This value maps to the limits field for memory for the created pod.

Important

If you have not set spec.podSpec.memory or spec.podSpec.memoryRequests:

  • Monitoring tools report incorrect available memory capacity.
  • The WiredTiger cache cannot be calculated correctly. This impacts cluster performance.
spec.podSpec.memoryRequests

Type: string

Minimum memory capacity for the node being created to host this standalone database MongoDB Kubernetes resource. If omitted, this value is set to spec.podSpec.memory.

This value maps to the requests field for memory for the created pod.

The requested value must be less than or equal to spec.podSpec.memory.

Note

For production deployments, MongoDB recommends setting this value to 16Gi. This value is consistent with considerations stated for MongoDB hosts.

spec.podSpec.nodeAffinity

Type: Struct

Kubernetes rule to place standalone database pods on a specific range of nodes.

Example

A user can isolate “dev” and “testing” environments to ensure pods go to nodes with appropriate labels.

spec.podSpec.persistence.single

Type: collection

Has Kubernetes Operator create one Persistent Volume Claim and mount all three directories for data, journal, and logs to the same Persistent Volume.

Note

  • You must set the values in this collection if spec.persistent : true.
  • You may set this collection or the persistence.multiple collections but not both.
Scalar Data Type Description
labelSelector string Tag used to bind mounted volumes to directories.
storage string

Minimum size of Persistent Volume that should be mounted. This value is expressed as an integer followed by a unit of storage in JEDEC notation.

Default value is 16G.

Example

If this MongoDB Kubernetes resource requires 60 gigabytes of storage space, set this value to 60G.

storageClass string

Type of storage specified in a Persistent Volume Claim. You may create this storage type as a StorageClass object before using it in this object specification.

Note

Make sure to set the StorageClass reclaimPolicy to Retain. This ensures that data is retained when a Persistent Volume Claim is removed.

spec.podSpec.persistence.multiple.data

Type: collection

Has Kubernetes Operator create a Persistent Volume Claim and mount a directory for data to its own Persistent Volume.

Note

  • You must set the values in this collection if spec.persistent : true.
  • You may set this collection or the persistence.single collection but not both.
Scalar Data Type Description
labelSelector string Tag used to bind mounted volumes to directories.
storage string

Minimum storage capacity that must be available on a Kubernetes node to host this standalone deployment on Kubernetes. This value is expressed as an integer followed by a unit of storage in JEDEC notation.

Default value is 16G.

Example

If this MongoDB Kubernetes resource requires 60 gigabytes of storage space, set this value to 60G.

storageClass string

Type of storage needed for this standalone deployment. You may create this storage type as a StorageClass object before using it in this object specification.

Note

Make sure to set the StorageClass reclaimPolicy to Retain. This ensures that data is retained when a Persistent Volume Claim is removed.

spec.podSpec.persistence.multiple.journal

Type: collection

Has Kubernetes Operator create a Persistent Volume Claim and mount a directory for journal to its own Persistent Volume.

Note

  • You must set the values in this collection if spec.persistent : true.
  • You may set this collection or the persistence.single collection but not both.
Scalar Data Type Description
labelSelector string Tag used to bind mounted volumes to directories.
storage string

Minimum storage capacity that must be available on a Kubernetes node to host this standalone deployment on Kubernetes. This value is expressed as an integer followed by a unit of storage in JEDEC notation.

Default value is 1G.

Example

If this MongoDB Kubernetes resource requires 60 gigabytes of storage space, set this value to 60G.

storageClass string

Type of storage needed for this standalone deployment. You may create this storage type as a StorageClass object before using it in this object specification.

Note

Make sure to set the StorageClass reclaimPolicy to Retain. This ensures that data is retained when a Persistent Volume Claim is removed.

spec.podSpec.persistence.multiple.logs

Type: collection

Has Kubernetes Operator create a Persistent Volume Claim and mount a directory for logs to its own Persistent Volume.

Note

  • You must set the values in this collection if spec.persistent : true.
  • You may set this collection or the persistence.single collection but not both.
Scalar Data Type Description
labelSelector string Tag used to bind mounted volumes to directories.
storage string

Minimum storage capacity that must be available on a Kubernetes node to host this standalone deployment on Kubernetes. This value is expressed as an integer followed by a unit of storage in JEDEC notation.

Default value is 3G.

Example

If this MongoDB Kubernetes resource requires 60 gigabytes of storage space, set this value to 60G.

storageClass string

Type of storage needed for this standalone deployment. You may create this storage type as a StorageClass object before using it in this object specification.

Note

Make sure to set the StorageClass reclaimPolicy to Retain. This ensures that data is retained when a Persistent Volume Claim is removed.

spec.podSpec.podAffinity

Type: Struct

Kubernetes rule to determine if multiple MongoDB Kubernetes resource pods must be co-located with other pods.

See also

The Kubernetes documentation for use cases on affinity and anti-affinity

Replica Set Settings

Note

All of the Standalone Settings also apply to replica set resources.

The following settings only apply to replica set resource types:

spec.members

Type: integer

Required. Number of Members of the Replica Set.

spec.podSpec.podAntiAffinityTopologyKey

Type: string

Default: kubernetes.io/hostname

This sets a rule to spread MongoDB Kubernetes resource pods to different locations. A location can be a single node, rack, or region. This key defines which node label is used to determine equal location for nodes. By default, Kubernetes Operator tries to spread pods across different hosts.

Sharded Cluster Settings

The following settings only apply to sharded cluster resource types:

spec.exposedExternally

Type: boolean

Default: false

Determines whether the MongoDB deployment is exposed outside of the Kubernetes cluster. This results in Kubernetes creating a NodePort service.

spec.configServerCount

Type: integer

Required. Number of Members in the Config Server.

spec.configSrvPodSpec.cpu

Type: number

Maximum CPU capacity that must be available on a Kubernetes node to host this sharded cluster config server member MongoDB Kubernetes resource.

This value maps to the limits field for CPU for the created pod.

spec.configSrvPodSpec.cpuRequests

Type: string

Minimum CPU capacity for the node being created to host this sharded cluster config server member MongoDB Kubernetes resource. If omitted, this value is set to spec.configSrvPodSpec.cpu.

This value maps to the requests field for CPU for the created pod.

The requested value must be less than or equal to spec.configSrvPodSpec.cpu.

Note

For production deployments, MongoDB recommends setting this value to 2. This value is consistent with considerations stated for MongoDB hosts.

spec.configSrvPodSpec.memory

Type: string

Maximum memory capacity that must be available on a Kubernetes node to host this MongoDB Kubernetes resource on Kubernetes. This value is expressed as an integer followed by a unit of memory in JEDEC notation.

Example

If this MongoDB Kubernetes resource requires 4 gigabytes of memory, set this value to 4G.

This value maps to the limits field for memory for the created pod.

Important

If you have not set spec.configSrvPodSpec.memory or spec.configSrvPodSpec.memoryRequests:

  • Monitoring tools report incorrect available memory capacity.
  • The WiredTiger cache cannot be calculated correctly. This impacts cluster performance.
spec.configSrvPodSpec.memoryRequests

Type: string

Minimum memory capacity for the node being created to host this standalone database MongoDB Kubernetes resource. If omitted, this value is set to spec.podSpec.memory.

This value maps to the requests field for memory for the created pod.

The requested value must be less than or equal to spec.podSpec.memory.

Note

For production deployments, MongoDB recommends setting this value to 16Gi. This value is consistent with considerations stated for MongoDB hosts.

spec.configSrvPodSpec.persistence.single

Type: collection

Has Kubernetes Operator create one Persistent Volume Claim and mount all three directories for data, journal, and logs to the same Persistent Volume.

Note

  • You must set the values in this collection if spec.persistent : true.
  • You may set this collection or the persistence.multiple collections but not both.
Scalar Data Type Description
labelSelector string Tag used to bind mounted volumes to directories.
storage string

Minimum size of Persistent Volume that should be mounted. This value is expressed as an integer followed by a unit of storage in JEDEC notation.

Default value is 5G.

Example

If this MongoDB Kubernetes resource requires 60 gigabytes of storage space, set this value to 60G.

storageClass string

Type of storage specified in a Persistent Volume Claim. You may create this storage type as a StorageClass object before using it in this object specification.

Note

Make sure to set the StorageClass reclaimPolicy to Retain. This ensures that data is retained when a Persistent Volume Claim is removed.

spec.configSrvPodSpec.persistence.multiple.data

Type: collection

Has Kubernetes Operator create a Persistent Volume Claim and mount a directory for data to its own Persistent Volume.

Note

  • You must set the values in this collection if spec.persistent : true.
  • You may set this collection or the persistence.single collection but not both.
Scalar Data Type Description
labelSelector string Tag used to bind mounted volumes to directories.
storage string

Minimum storage capacity that must be available on a Kubernetes node to host this sharded cluster config server member on Kubernetes. This value is expressed as an integer followed by a unit of storage in JEDEC notation.

Default value is 16G.

Example

If this MongoDB Kubernetes resource requires 60 gigabytes of storage space, set this value to 60G.

storageClass string

Type of storage needed for this sharded cluster config server member. You may create this storage type as a StorageClass object before using it in this object specification.

Note

Make sure to set the StorageClass reclaimPolicy to Retain. This ensures that data is retained when a Persistent Volume Claim is removed.

spec.configSrvPodSpec.persistence.multiple.journal

Type: collection

Has Kubernetes Operator create a Persistent Volume Claim and mount a directory for journal to its own Persistent Volume.

Note

  • You must set the values in this collection if spec.persistent : true.
  • You may set this collection or the persistence.single collection but not both.
Scalar Data Type Description
labelSelector string Tag used to bind mounted volumes to directories.
storage string

Minimum storage capacity that must be available on a Kubernetes node to host this sharded cluster config server member on Kubernetes. This value is expressed as an integer followed by a unit of storage in JEDEC notation.

Default value is 1G.

Example

If this MongoDB Kubernetes resource requires 60 gigabytes of storage space, set this value to 60G.

storageClass string

Type of storage needed for this sharded cluster config server member. You may create this storage type as a StorageClass object before using it in this object specification.

Note

Make sure to set the StorageClass reclaimPolicy to Retain. This ensures that data is retained when a Persistent Volume Claim is removed.

spec.configSrvPodSpec.persistence.multiple.logs

Type: collection

Has Kubernetes Operator create a Persistent Volume Claim and mount a directory for logs to its own Persistent Volume.

Note

  • You must set the values in this collection if spec.persistent : true.
  • You may set this collection or the persistence.single collection but not both.
Scalar Data Type Description
labelSelector string Tag used to bind mounted volumes to directories.
storage string

Minimum storage capacity that must be available on a Kubernetes node to host this sharded cluster config server member on Kubernetes. This value is expressed as an integer followed by a unit of storage in JEDEC notation.

Default value is 3G.

Example

If this MongoDB Kubernetes resource requires 60 gigabytes of storage space, set this value to 60G.

storageClass string

Type of storage needed for this sharded cluster config server member. You may create this storage type as a StorageClass object before using it in this object specification.

Note

Make sure to set the StorageClass reclaimPolicy to Retain. This ensures that data is retained when a Persistent Volume Claim is removed.

spec.configSrvPodSpec.nodeAffinity

Type: collection

Kubernetes rule to place sharded cluster config server member pods on a specific range of nodes.

Example

A user can isolate “dev” and “testing” environments to ensure pods go to nodes with appropriate labels.

spec.configSrvPodSpec.podAffinity

Type: collection

Kubernetes rule to determine if multiple MongoDB Kubernetes resource pods must be co-located with other pods.

See also

The Kubernetes documentation for use cases on affinity and anti-affinity

spec.configSrvPodSpec.podAntiAffinityTopologyKey

Type: string

Default: kubernetes.io/hostname

This sets a rule to spread MongoDB Kubernetes resource pods to different locations. A location can be a single node, rack, or region. This key defines which node label is used to determine equal location for nodes. By default, Kubernetes Operator tries to spread pods across different hosts.

spec.mongodsPerShardCount

Type: integer

Required. Number of Members per shard.

spec.mongosCount

Type: integer

Required. Number of Shard Routers.

spec.mongosPodSpec.cpu

Type: number

Maximum CPU capacity that must be available on a Kubernetes node to host this sharded cluster shard member MongoDB Kubernetes resource.

This value maps to the limits field for CPU for the created pod.

spec.mongosPodSpec.cpuRequests

Type: string

Minimum CPU capacity for the node being created to host this standalone database MongoDB Kubernetes resource. If omitted, this value is set to spec.mongosPodSpec.cpu.

This value maps to the requests field for CPU for the created pod.

The requested value must be less than or equal to spec.mongosPodSpec.cpu.

Note

For production deployments, MongoDB recommends setting this value to 2. This value is consistent with considerations stated for MongoDB hosts.

spec.mongosPodSpec.memory

Type: string

Maximum memory capacity that must be available on a Kubernetes node to host this MongoDB Kubernetes resource on Kubernetes. This value is expressed as an integer followed by a unit of memory in JEDEC notation.

Example

If this MongoDB Kubernetes resource requires 4 gigabytes of memory, set this value to 4G.

This value maps to the limits field for memory for the created pod.

Important

If you have not set spec.mongosPodSpec.memory or spec.mongosPodSpec.memoryRequests:

  • Monitoring tools report incorrect available memory capacity.
  • The WiredTiger cache cannot be calculated correctly. This impacts cluster performance.
spec.mongosPodSpec.memoryRequests

Type: string

Minimum memory capacity for the node being created to host this sharded cluster shard member MongoDB Kubernetes resource. If omitted, this value is set to spec.podSpec.memory.

This value maps to the requests field for memory for the created pod.

The requested value must be less than or equal to spec.podSpec.memory.

Note

For production deployments, MongoDB recommends setting this value to 16Gi. This value is consistent with considerations stated for MongoDB hosts.

spec.mongosPodSpec.nodeAffinity

Type: collection

Optional. Kubernetes rule to determine if multiple MongoDB Kubernetes resource nodes must be co-located with other nodes.

spec.mongosPodSpec.podAffinity

Type: collection

Optional. Kubernetes rule to determine if multiple MongoDB Kubernetes resource pods must be co-located with other pods.

spec.mongosPodSpec.podAntiAffinityTopologyKey

Type: string

Default: kubernetes.io/hostname

This sets a rule to spread MongoDB Kubernetes resource pods to different locations. A location can be a single node, rack, or region. This key defines which node label is used to determine equal location for nodes. By default, Kubernetes Operator tries to spread pods across different hosts.

spec.shardCount

Type: integer

Required. Number of Shards in the sharded cluster.

spec.shardPodSpec.cpu

Type: number

Maximum CPU capacity that must be available on a Kubernetes node to host this sharded cluster shard member MongoDB Kubernetes resource.

This value maps to the limits field for CPU for the created pod.

spec.shardPodSpec.cpuRequests

Type: string

Minimum CPU capacity for the node being created to host this sharded cluster shard member MongoDB Kubernetes resource. If omitted, this value is set to spec.shardPodSpec.cpu.

This value maps to the requests field for CPU for the created pod.

The requested value must be less than or equal to spec.shardPodSpec.cpu.

Note

For production deployments, MongoDB recommends setting this value to 2. This value is consistent with considerations stated for MongoDB hosts.

spec.shardPodSpec.memory

Type: string

Maximum memory capacity that must be available on a Kubernetes node to host this MongoDB Kubernetes resource on Kubernetes. This value is expressed as an integer followed by a unit of memory in JEDEC notation.

Example

If this MongoDB Kubernetes resource requires 4 gigabytes of memory, set this value to 4G.

This value maps to the limits field for memory for the created pod.

Important

If you have not set spec.shardPodSpec.memory or spec.shardPodSpec.memoryRequests:

  • Monitoring tools report incorrect available memory capacity.
  • The WiredTiger cache cannot be calculated correctly. This impacts cluster performance.
spec.shardPodSpec.memoryRequests

Type: string

Minimum memory capacity for the node being created to host this sharded cluster shard member MongoDB Kubernetes resource. If omitted, this value is set to spec.podSpec.memory.

This value maps to the requests field for memory for the created pod.

The requested value must be less than or equal to spec.podSpec.memory.

Note

For production deployments, MongoDB recommends setting this value to 16Gi. This value is consistent with considerations stated for MongoDB hosts.

spec.shardPodSpec.nodeAffinity

Type: string

Kubernetes rule to place shard pods on a specific range of nodes.

Example

A user can isolate “dev” and “testing” environments to ensure pods go to nodes with appropriate labels.

spec.shardPodSpec.persistence.single

Type: collection

Has Kubernetes Operator create one Persistent Volume Claim and mount all three directories for data, journal, and logs to the same Persistent Volume.

Note

  • You must set the values in this collection if spec.persistent : true.
  • You may set this collection or the persistence.multiple collections but not both.
Scalar Data Type Description
labelSelector string Tag used to bind mounted volumes to directories.
storage string

Minimum size of Persistent Volume that should be mounted. This value is expressed as an integer followed by a unit of storage in JEDEC notation.

Default value is 16G.

Example

If this MongoDB Kubernetes resource requires 60 gigabytes of storage space, set this value to 60G.

storageClass string

Type of storage specified in a Persistent Volume Claim. You may create this storage type as a StorageClass object before using it in this object specification.

Note

Make sure to set the StorageClass reclaimPolicy to Retain. This ensures that data is retained when a Persistent Volume Claim is removed.

spec.shardPodSpec.persistence.multiple.data

Type: collection

Has Kubernetes Operator create a Persistent Volume Claim and mount a directory for data to its own Persistent Volume.

Note

  • You must set the values in this collection if spec.persistent : true.
  • You may set this collection or the persistence.single collection but not both.
Scalar Data Type Description
labelSelector string Tag used to bind mounted volumes to directories.
storage string

Minimum storage capacity that must be available on a Kubernetes node to host this sharded cluster shard member on Kubernetes. This value is expressed as an integer followed by a unit of storage in JEDEC notation.

Default value is 16G.

Example

If this MongoDB Kubernetes resource requires 60 gigabytes of storage space, set this value to 60G.

storageClass string

Type of storage needed for this sharded cluster shard member. You may create this storage type as a StorageClass object before using it in this object specification.

Note

Make sure to set the StorageClass reclaimPolicy to Retain. This ensures that data is retained when a Persistent Volume Claim is removed.

spec.shardPodSpec.persistence.multiple.journal

Type: collection

Has Kubernetes Operator create a Persistent Volume Claim and mount a directory for journal to its own Persistent Volume.

Note

  • You must set the values in this collection if spec.persistent : true.
  • You may set this collection or the persistence.single collection but not both.
Scalar Data Type Description
labelSelector string Tag used to bind mounted volumes to directories.
storage string

Minimum storage capacity that must be available on a Kubernetes node to host this sharded cluster shard member on Kubernetes. This value is expressed as an integer followed by a unit of storage in JEDEC notation.

Default value is 1G.

Example

If this MongoDB Kubernetes resource requires 60 gigabytes of storage space, set this value to 60G.

storageClass string

Type of storage needed for this sharded cluster shard member. You may create this storage type as a StorageClass object before using it in this object specification.

Note

Make sure to set the StorageClass reclaimPolicy to Retain. This ensures that data is retained when a Persistent Volume Claim is removed.

spec.shardPodSpec.persistence.multiple.logs

Type: collection

Has Kubernetes Operator create a Persistent Volume Claim and mount a directory for logs to its own Persistent Volume.

Note

  • You must set the values in this collection if spec.persistent : true.
  • You may set this collection or the persistence.single collection but not both.
Scalar Data Type Description
labelSelector string Tag used to bind mounted volumes to directories.
storage string

Minimum storage capacity that must be available on a Kubernetes node to host this sharded cluster shard member on Kubernetes. This value is expressed as an integer followed by a unit of storage in JEDEC notation.

Default value is 3G.

Example

If this MongoDB Kubernetes resource requires 60 gigabytes of storage space, set this value to 60G.

storageClass string

Type of storage needed for this sharded cluster shard member. You may create this storage type as a StorageClass object before using it in this object specification.

Note

Make sure to set the StorageClass reclaimPolicy to Retain. This ensures that data is retained when a Persistent Volume Claim is removed.

spec.shardPodSpec.podAffinity

Type: string

Kubernetes rule to determine if multiple MongoDB Kubernetes resource pods must be co-located with other pods.

See also

The Kubernetes documentation for use cases on affinity and anti-affinity

spec.shardPodSpec.podAntiAffinityTopologyKey

Type: string

Default: kubernetes.io/hostname

This sets a rule to spread MongoDB Kubernetes resource pods to different locations. A location can be a single node, rack, or region. This key defines which node label is used to determine equal location for nodes. By default, Kubernetes Operator tries to spread pods across different hosts.

Security Settings

The following TLS settings only apply to replica set and sharded cluster resource types:

spec.security.tls.enabled

Type: boolean

Default: false

Encrypts communications using TLS certificates between:

  • MongoDB hosts in a replica set or sharded cluster configuration
  • Clients (mongo shell, drivers, MongoDB Compass, and others) and the MongoDB deployment

By default, net.ssl.mode is set to requireSSL. To change the TLS mode used for client and database connections, see spec.additionalMongodConfig.net.ssl.mode.

spec.additionalMongodConfig.net.ssl.mode

Type: string

Default: requireSSL

Specifies which sslMode is used for network connections. The following are valid options:

Value Description
allowSSL Connections between servers do not use TLS. For incoming connections, the server accepts both TLS and non-TLS.
preferSSL Connections between servers use TLS. For incoming connections, the server accepts both TLS and non-TLS.
requireSSL The server uses and accepts only TLS encrypted connections.
spec.security.authentication.enabled

Type: boolean

Default: false

Specifies whether x.509 authentication is enabled on the Cloud Manager or Ops Manager project.

spec.security.authentication.modes

Type: array

Set to ["X509"] to enable X.509 internal cluster authentication for the Cloud Manager or Ops Manager project.

spec.security.authentication.internalCluster

Type: string

Set to X509 to enable X.509 internal cluster authentication. Requires TLS on the resource by setting spec.security.tls.enabled to true.

Important

Once internal cluster authentication is enabled, it can not be disabled.

(Changed in version 1.3):

In prior versions of the MongoDB Enterprise Kubernetes Operator, this setting was spec.security.clusterAuthenticationMode. See the v1.2 documentation for information on the previous setting name.

Examples

The following example shows a resource specification for a standlone deployment with every setting provided:

apiVersion: mongodb.com/v1
kind: MongoDB
metadata:
  name: my-standalone
  namespace: mongodb
spec:
  version: 4.0.0
  service: my-service
  opsManager: # Alias of cloudManager
    configMapRef:
      name: my-project
  credentials: my-credentials
  persistent: true
  type: Standalone
  podSpec:
    cpu: '0.25'
    memory: 512M
    persistence:
      single:
        storage: 12G
        storageClass: standard
        labelSelector:
          matchExpressions:
          - {key: environment, operator: In, values: [dev]}
    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
...

The following example shows a resource specification for a replica set with every setting provided:

---
apiVersion: mongodb.com/v1
kind: MongoDB
metadata:
  name: my-replica-set
  namespace: mongodb
spec:
  members: 3
  version: 4.0.0
  service: my-service
  opsManager: # Alias of cloudManager
    configMapRef:
      name: my-project
  credentials: my-credentials
  persistent: true
  type: ReplicaSet
  podSpec:
    cpu: '0.25'
    memory: 512M
    persistence:
      multiple:
        data:
          storage: 10Gi
        journal:
          storage: 1Gi
          labelSelector:
            matchLabels:
              app: "my-app"
        logs:
          storage: 500M
          storageClass: standard
    podAntiAffinityTopologyKey: nodeId
    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
  security:
    tls:
      enabled: true
    authentication:
      enabled: true
      modes: ["X509"]
      internalCluster: "X509"
  additionalMongodConfig:
    net:
      ssl:
        mode: requireSSL
...

The following example shows a resource specification for a sharded cluster with every setting provided:

---
apiVersion: mongodb.com/v1
kind: MongoDB
metadata:
  name: my-sharded-cluster
  namespace: mongodb
spec:
  shardCount: 2
  mongodsPerShardCount: 3
  mongosCount: 2
  configServerCount: 3
  version: 4.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 `clusterName` attribute.

  opsManager: # Alias of cloudManager
    configMapRef:
      name: my-project
  credentials: my-credentials

  persistent: true
  configSrvPodSpec:
    cpu: '0.5'
    memory: 512M

    # if "persistence" element is omitted then Operator uses the
    # default size (5G) for mounting single Persistent Volume

    podAntiAffinityTopologyKey: kubernetes.io/hostname
    podAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
      - labelSelector:
          matchExpressions:
          - key: security
            operator: In
            values:
            - S1
        topologyKey: failure-domain.beta.kubernetes.io/zone
  mongosPodSpec:
    cpu: '0.8'
    memory: 1G
    podAntiAffinityTopologyKey: rackId
    nodeAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 1
        preference:
          matchExpressions:
          - key: another-node-label-key
            operator: In
            values:
            - another-node-label-value
  shardPodSpec:
    cpu: '0.6'
    memory: 3G
    persistence:
      multiple:
        # if the child of "multiple" is omitted then the default size will be used.
        # 16G for "data", 1G for "journal", 3Gb for "logs"
        data:
          storage: 20G
        logs:
          storage: 4G
          storageClass: standard
    podAntiAffinityTopologyKey: kubernetes.io/hostname
  security:
    tls:
      enabled: true
    authentication:
      enabled: true
      modes: ["X509"]
      internalCluster: "X509"
  additionalMongodConfig:
    net:
      ssl:
        mode: requireSSL
...