liveBook · Manning

MongoDBCommunity

As explained in Kubernetes in Action, Second Edition

A custom Kubernetes API object type representing the desired configuration of a MongoDB Community deployment managed by an operator.

MongoDBCommunity is a Kubernetes API object representing the desired configuration of a MongoDB Community deployment. A CustomResourceDefinition adds this object type to the cluster API, allowing the operator to manage MongoDB without directly creating StatefulSets and related objects. section 16.4.1 section 16.4.2

A three-member replica set

A MongoDBCommunity manifest can request three ReplicaSet members, a MongoDB version, SCRAM authentication, and configured users. Applying it with kubectl creates the MongoDBCommunity object and its referenced password Secret. section 16.4.2

The object follows the familiar Kubernetes manifest structure:

  • apiVersion and kind identify the MongoDBCommunity API type. section 16.4.2
  • metadata.name identifies the MongoDB deployment. section 16.4.2
  • spec declares the MongoDB type, version, replica-set size, authentication, and users. section 16.4.2

The operator reconciles the object and creates a StatefulSet, Services, and Secrets. Core controllers then create the pods, while the operator automatically initiates the MongoDB replica set. Direct changes to managed objects, such as scaling the StatefulSet, are undone by reconciliation. section 16.4.2

Listing 16.9 The MongoDBCommunity custom object manifest
apiVersion: mongodbcommunity.mongodb.com/v1      #1
kind: MongoDBCommunity                #1          
metadata:
  name: example-mongodb     #2
spec:
  members: 3             #3
  type: ReplicaSet       #3
  version: "4.2.6"               #4
  security:                              #5
    authentication:                     #5
      modes: ["SCRAM"]                  #5
  users:                                #5
    - name: my-user                     #5
      db: admin                         #5
      passwordSecretRef:                #5
        name: my-user-password          #5
      roles:                            #5
        - name: clusterAdmin            #5
          db: admin                     #5
        - name: userAdminAnyDatabase                             #5
          db: admin                                             #5
      scramCredentialsSecretName: my-scram                      #5
  additionalMongodConfig:                                       #5
    storage.wiredTiger.engineConfig.journalCompressor: zlib  #5

Inspect the complete MongoDBCommunity manifest, including replica-set members, version, authentication, users, roles, and Secret references. section 16.4.2

How Kubernetes in Action, Second Edition covers it

How deep it goes
Defines manifest fields and follows reconciliation through generated StatefulSets, Services, Secrets, pods, and replica-set initialization.
Examples
Uses a three-member ReplicaSet manifest with MongoDB version 4.2.6, SCRAM authentication, users, roles, and Secret references.
What it assumes
Requires a Kubernetes cluster with the MongoDB Community operator and its CustomResourceDefinition installed first.
What you can do after
Apply it via kubectl to request a MongoDB replica set without manually creating StatefulSets or initiating the replica set.
How it connects
Connects CustomResourceDefinition, operator reconciliation, StatefulSet, Services, Secrets, core controllers, and MongoDB replica sets.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.