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
