Navigation
  • Reference >
  • MongoDB Kubernetes Object Specification

MongoDB Kubernetes Object Specification

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 Object 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. Type of MongoDB Kubernetes resource to create. Accepted values are:

  • MongoDbStandalone
  • MongoDbReplicaSet
  • MongoDbShardedCluster
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.project

Type: string

Required. Name given to the Project object as defined in its ConfigMap. This value must be the match the metadata.name value in the ConfigMap.

spec.credentials

Type: string

Required. Name of the Kubernetes secret created as Ops Manager Application Programming Interface authentication credentials for the Kubernetes Operator to communicate with Ops Manager.

spec.version

Type: number

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

Optional

Every resource type may use the following settings:

spec.service

Type: string

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

Optional. 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.clusterName

Type: string

Default: cluster.local

Optional. When Kubernetes creates a StatefulSet, the Kubernetes assigns each pod a FQDN. To update Ops Manager, the Kubernetes Operator calculates the FQDN for each pod using a provided clusterName. Kubernetes does not provide an Application Programming Interface to query these hostnames.

spec.persistent

Type: boolean

Default: 1

Optional. Flag indicating if this MongoDB Kubernetes resource should use persistent volumes for storage.

Deployment Item 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.

spec.podSpec.cpu

Type: string

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

spec.podSpec.memory

Type: string

Optional. Minimum 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.

spec.podSpec.storage

Type: string

Default: 16G

Optional. Minimum storage 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 storage in JEDEC notation.

Example

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

spec.podSpec.storageClass

Type: string

Optional. Type of storage needed for this standalone database. The user may create this storage type as a StorageClass object before using it in this object specification.

spec.podSpec.podAffinity

Type: Struct

Optional. 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.podSpec.nodeAffinity

Type: Struct

Optional. 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.members

Type: integer

Required. Number of Members of the Replica Set.

spec.podSpec.podAntiAffinityTopologyKey

Type: string

Default: kubernetes.io/hostname

Optional. 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.mongodsPerShardCount

Type: integer

Required. Number of Members per Shard.

spec.mongosCount

Type: integer

Required. Number of Shard Routers.

spec.configServerCount

Type: integer

Required. Number of Members in the Config Server.

spec.configSrvPodSpec.cpu

Type: number

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

spec.configSrvPodSpec.memory

Type: string

Optional. Minimum 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.

spec.configSrvPodSpec.storage

Type: string

Default: 5G

Optional. Minimum storage 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 storage in JEDEC notation.

Example

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

spec.configSrvPodSpec.storageClass

Type: string

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

spec.configSrvPodSpec.podAntiAffinityTopologyKey

Default: kubernetes.io/hostname

Optional. 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.configSrvPodSpec.podAffinity

Optional. 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.mongosPodSpec.cpu

Type: number

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

spec.mongosPodSpec.memory

Type: string

Optional. Minimum 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.

spec.mongosPodSpec.podAntiAffinityTopologyKey

Default: kubernetes.io/hostname

Optional. 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.mongosPodSpec.nodeAffinity.preferredDuringSchedulingIgnoredDuringExecution

Type: Struct

Optional. If nodes match the rules, those nodes are chosen first, and only if no preferred nodes are available are non-preferred nodes chosen.

spec.shardPodSpec.cpu

Type: number

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

spec.shardPodSpec.memory

Type: string

Optional. Minimum 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.

spec.shardPodSpec.storage

Type: string

Default: 16G

Optional. Minimum storage 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 storage in JEDEC notation.

Example

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

spec.shardPodSpec.storageClass

Type: string

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

spec.shardPodSpec.podAntiAffinityTopologyKey

Default: kubernetes.io/hostname

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

Example

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

apiVersion: mongodb.com/v1
kind: MongoDbStandalone
metadata:
  name: my-standalone
  namespace: mongodb
spec:
  version: 3.6.3
  service: my-service
  clusterName: example.com
  project: my-project
  credentials: my-credentials

  persistent: true
  podSpec:
    cpu: '0.25'
    memory: 512M
    storage: 12G
    storageClass: standard
    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: MongoDbReplicaSet
metadata:
  name: my-replica-set
  namespace: mongodb
spec:
  members: 3
  version: 3.6.4
  # service allows to override the name of Kubernetes service that is created for stateful set
  service: my-service

  ## Please Note: Kubernetes cluster default name is `cluster.local`.
  ## If your cluster has been configured with another name, you can specify
  ## it with the `clusterName` attribute.
  #
  # clusterName: mycompany.net

  project: my-project
  credentials: my-credentials

  persistent: true
  podSpec:
    cpu: '0.25'
    memory: 512M
    storage: 12G
    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

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

---
apiVersion: mongodb.com/v1
kind: MongoDbShardedCluster
metadata:
  name: my-sharded-cluster
  namespace: mongodb
spec:
  shardCount: 2
  mongodsPerShardCount: 3
  mongosCount: 2
  configServerCount: 3
  version: 3.6.3
  service: my-service
  clusterName: example.com
  project: my-project
  credentials: my-credentials

  persistent: true
  configSrvPodSpec:
    cpu: '0.5'
    memory: 512M
    storage: 5G
    storageClass: fast
    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: failure-domain.beta.kubernetes.io/region
    nodeAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 1
        preference:
          matchExpressions:
          - key: another-node-label-key
            operator: In
            values:
            - another-node-label-value
  shardPodSpec:
    cpu: '0.6'
    memory: 3G
    storage: 25G
    storageClass: standard
    podAntiAffinityTopologyKey: rackId