You can deploy MongoDB Search and Vector Search alongside MongoDB 8.2 or later using MongoDB Controllers for Kubernetes Operator.
Example Resource Specification
The following example shows the settings inside the spec object for MongoDB Search and Vector Search deployment. To learn more about these settings, see the Required Settings and Optional Settings.
Note
This example is not a working configuration. It contains all available fields populated with sample values for reference. Some fields are mutually exclusive, and some take precedence over others (for example, source.external takes precedence over source.mongodbResourceRef). Refer to the field descriptions below for valid combinations.
Example
1 spec: 2 source: 3 # external takes precedence over mongodbResourceRef 4 mongodbResourceRef: 5 name: mdb 6 external: 7 # hostAndPorts and shardedCluster are mutually exclusive 8 hostAndPorts: 9 - mdb-rs-external-0.example.com:27017 10 - mdb-rs-external-1.example.com:27017 11 - mdb-rs-external-2.example.com:27017 12 shardedCluster: 13 router: 14 hosts: 15 - mongos1.example.com:27017 16 - mongos2.example.com:27017 17 shards: 18 - shardName: shard-0 19 hosts: 20 - shard0-node1.example.com:27018 21 - shard0-node2.example.com:27018 22 - shardName: shard-1 23 hosts: 24 - shard1-node1.example.com:27018 25 - shard1-node2.example.com:27018 26 keyfileSecretRef: 27 name: mdb-keyfile 28 key: keyfile 29 tls: 30 # ca references a ConfigMap that contains ca.crt 31 ca: 32 name: mdbc-rs-ca 33 username: search-sync-source 34 passwordSecretRef: 35 name: mdbc-rs-search-sync-source-password 36 key: password 37 # x509 authentication (mutually exclusive with 38 # username/passwordSecretRef and source.tls) 39 x509: 40 clientCertificateSecretRef: 41 name: mongot-x509-client-cert 42 # Set only if the private key is encrypted 43 keyFilePasswordSecretRef: 44 name: mongot-x509-key-password 45 # TLS client certificate for SCRAM connections 46 # (mutually exclusive with x509): 47 # tls: 48 # clientCertificateSecretRef: 49 # name: mongot-scram-client-cert 50 # keyFilePasswordSecretRef: 51 # name: mongot-scram-key-password 52 security: 53 tls: 54 certificateKeySecretRef: 55 name: mdbs-tls-secret 56 certsSecretPrefix: my-prefix 57 # Set only if the private key is encrypted 58 keyFilePasswordSecretRef: 59 name: mdbs-tls-key-password 60 version: "1.70.1" 61 autoEmbedding: 62 embeddingModelAPIKeySecret: 63 name: embedding-model-api-query-key 64 providerEndpoint: https://ai.mongodb.com/v1/embeddings 65 featureFlags: 66 enableOverloadRetrySignal: true 67 logLevel: INFO 68 observability: 69 prometheus: 70 mode: enabled 71 port: 9946 72 metricsForwarder: 73 mode: auto 74 resourceRequirements: 75 requests: 76 cpu: 100m 77 memory: 128Mi 78 limits: 79 cpu: 250m 80 memory: 256Mi 81 deployment: 82 spec: 83 template: 84 spec: 85 nodeSelector: 86 kubernetes.io/os: linux 87 opsManager: 88 agentCredentials: 89 name: om-agent-api-key 90 projectConfigMapRef: 91 name: om-project-config 92 clusters: 93 - name: cluster-1 94 index: 0 95 replicas: 2 96 loadBalancer: 97 # Option 1: Operator-managed Envoy load balancer 98 managed: 99 externalHostname: "{shardName}.search.apps.example.com" 100 routerHostname: "search-router.apps.example.com:27028" 101 replicas: 2 102 resourceRequirements: 103 requests: 104 cpu: "100m" 105 memory: 128Mi 106 limits: 107 cpu: "500m" 108 memory: 512Mi 109 deployment: 110 spec: 111 template: 112 spec: 113 nodeSelector: 114 kubernetes.io/os: linux 115 retryPolicy: 116 numRetries: 2 117 perTryTimeout: "60s" 118 minMongotReadyReplicas: 1 119 # Option 2: User-provided (BYO) load balancer 120 # (mutually exclusive with managed) 121 unmanaged: 122 endpoint: "{shardName}-search-lb.corp.example.com:443" 123 resourceRequirements: 124 limits: 125 cpu: "3" 126 memory: 5Gi 127 requests: 128 cpu: "2" 129 memory: 4Gi 130 persistence: 131 single: 132 storage: 16G 133 storageClass: standard 134 statefulSet: 135 spec: 136 template: 137 spec: 138 nodeSelector: 139 kubernetes.io/os: linux 140 jvmFlags: 141 - -Xms2g 142 - -Xmx2g 143 advancedMongotConfigs: 144 someAdvancedSetting: value 145 syncSourceSelector: 146 matchTagSets: 147 - region: us-east-1 148 workload: search 149 - {} 150 shardOverrides: 151 - shardNames: 152 - shard-0 153 replicas: 3 154 resourceRequirements: 155 requests: 156 cpu: "4" 157 memory: 8Gi 158 persistence: 159 single: 160 storage: 32G 161 jvmFlags: 162 - -Xms4g 163 - -Xmx4g 164 statefulSet: 165 spec: 166 template: 167 spec: 168 nodeSelector: 169 disktype: ssd
Required Settings
This section describes the settings that are required for deploying the MongoDB Search and Vector Search resource. If you define only the required settings in the Custom Resource Definition (CRD), the MongoDB Controllers for Kubernetes Operator uses the defaults for all optional settings to configure MongoDBSearch.
apiVersionType: string
Version of the MongoDB Kubernetes resource schema. Set the value to
mongodb.com/v1.
kindType: string
Kind of MongoDB Kubernetes resource to create. Set this to MongoDBSearch.
metadata.namespaceType: string
Namespace in which to create the MongoDBSearch resource. To leverage automatic configuration of MongoDBSearch and
MongoDBorMongoDBCommunityresources, create the MongoDBSearch resource in the same namespace as theMongoDBorMongoDBCommunityresource.
metadata.nameType: string
Unique identifier of the MongoDBSearch resource. The name must be a valid Kubernetes DNS subdomain name. Keep the name short. The Kubernetes Operator derives the names of the Kubernetes resources it creates from it, for example
{name}-search-{clusterIndex}-{shardName}. The Kubernetes Operator validates that every generated name fits within the Kubernetes DNS limits of 63 characters for labels and 253 characters for subdomain names.spec.clustersType: array of objects
Per-Kubernetes-cluster deployment configuration for MongoDBSearch. This field is required and must contain at least one entry and at most 50 entries: one entry for a single-cluster deployment, or one entry for each Kubernetes cluster that runs
mongotpods in a multi-cluster deployment. For the full field reference, includingnameandindex, see spec.clusters.
Optional Settings
This section describes the optional settings for the MongoDB Search and Vector Search resource. If you omit the optional settings and define only the required settings in the CRD, the MongoDB Controllers for Kubernetes Operator uses the defaults for all optional settings to configure MongoDBSearch.
Settings for Configuring the Data Source
spec.sourceType: object
Setting that describes the MongoDB source for
mongot. The source can be a replica set or a sharded cluster. This setting is required if:MongoDBis externalMongoDBhas a different name from MongoDBSearch
The MongoDBSearch resource must always be connected to a MongoDB deployment. If you deployed using the Kubernetes Operator with
MongoDBorMongoDBCommunityCRD, and ifspec.sourceis empty, the Kubernetes Operator uses the following based on themetadata.nameto look for the database in Kubernetes:Find
MongoDBorMongoDBCommunityresources with the same name as set formetadata.namein MongoDBSearch, in the same namespace.Find the password secret for the
mongotuser from the<MongoDBSearch.metadata.name>-<username>-passwordsecret, which for the default username yields<MongoDBSearch.metadata.name>-search-sync-source-password.
spec.source.mongodbResourceRef.nameType: string
Name of the
MongoDBorMongoDBCommunityresource to associate with this MongoDB Search and Vector Search resource. The Kubernetes Operator supports both replica sets and sharded clusters. You can't have more than one MongoDBSearch resource referencing the sameMongoDBorMongoDBCommunityresource. If you specify a different name, you must explicitly point to theMongoDBorMongoDBCommunitywhere you want to enable MongoDB Search and Vector Search.If you reference a sharded cluster
MongoDBresource, the Kubernetes Operator auto-discovers the shard topology (shard names, replica set members,mongosrouters) and creates per-shardmongotStatefulSets automatically. You don't need to perform any additional external configuration.Use this field only if your
MongoDBorMongoDBCommunityresource is deployed in the same Kubernetes cluster and is in the same namespace as your MongoDBSearch resource. If you set this field, the Kubernetes Operator automatically:Sets proper connection strings to the database.
Reconfigures MongoDB database deployments by setting necessary parameters to enable search functionality and configures the addresses of the search pods.
If your database is deployed outside of Kubernetes or is in a different namespace, use
spec.source.externalto configure the connection to the database. If you set both fields,spec.source.externaltakes precedence.If omitted, the Kubernetes Operator looks for a
MongoDBorMongoDBCommunityresource with the same name as this MongoDBSearch resource.
spec.source.mongodbResourceRef.namespaceType: string
Namespace of the
MongoDBorMongoDBCommunityresource thatspec.source.mongodbResourceRef.namerefers to. The Kubernetes Operator currently ignores this field and always uses the namespace of the MongoDBSearch resource. Cross-namespace references are unsupported. If your database is in a different namespace, usespec.source.external.
Setting for Configuring mongot User
spec.source.usernameType: string
Username to use to authenticate
mongotwithmongod. The specified user must have thesearchCoordinatorrole. If omitted, the Kubernetes Operator assumes the username issearch-sync-source.
spec.source.passwordSecretRef.nameType: string
Name of the secret that contains the password that
mongotmust use to authenticate withmongod. If omitted, defaults to<MongoDBSearch.metadata.name>-<username>-password, where<username>is the value ofspec.source.username. For the default usernamesearch-sync-source, this yields<MongoDBSearch.metadata.name>-search-sync-source-password.
spec.source.passwordSecretRef.keyType: string
Key under which the password value is stored in the secret. If omitted, defaults to
password.
Settings for x509 Authentication
spec.source.x509Type: object
Configures x509 client certificate authentication for the
mongotsync source connection. If you set this field,mongotauthenticates to MongoDB using x509 instead of username and password.This field is mutually exclusive with
spec.source.passwordSecretRef,spec.source.username, andspec.source.tls. The Kubernetes Operator rejects the configuration if you specify both x509 and password authentication.
spec.source.x509.clientCertificateSecretRefType: object
Secret that contains the x509 client certificate and key for authenticating to the MongoDB sync source. The Secret must contain the following keys:
tls.crt— Client certificatetls.key— Private key
If the private key is encrypted with a password, store the password in a separate Secret and reference it with
spec.source.x509.keyFilePasswordSecretRef.You must specify this field if you set
spec.source.x509.Example
spec: source: x509: clientCertificateSecretRef: name: mongot-x509-client-cert
spec.source.x509.keyFilePasswordSecretRefType: object
Secret that contains the password that decrypts the password-encrypted private key in
spec.source.x509.clientCertificateSecretRef. The Secret must contain the password under thekeyFilePasswordkey. Omit this field if the private key is not encrypted.
Settings for TLS Client Certificates with SCRAM Authentication
spec.source.tlsType: object
Configures a TLS client certificate for the
mongotsync source connection if you use SCRAM (username and password) authentication. If you set this field,mongotpresents the client certificate during the TLS handshake with the source MongoDB deployment (mutual TLS transport).mongotstill authenticates with the username and password.Use this field only with SCRAM authentication (
spec.source.passwordSecretRef). This field is mutually exclusive withspec.source.x509. If you want the client certificate itself to serve as the authentication credential, usespec.source.x509instead.
spec.source.tls.clientCertificateSecretRefType: object
Secret that contains the TLS client certificate and key that
mongotpresents during the TLS handshake with the source MongoDB deployment. The Secret must contain the following keys:tls.crt— Client certificatetls.key— Private key
You must specify this field if you set
spec.source.tls.
spec.source.tls.keyFilePasswordSecretRefType: object
Secret that contains the password that decrypts the password-encrypted private key in
spec.source.tls.clientCertificateSecretRef. The Secret must contain the password under thekeyFilePasswordkey. Omit this field if the private key is not encrypted.
Settings for Connecting to External MongoDB
The following settings are required only for configuring a connection to an external MongoDB deployment.
spec.source.externalType: object
Settings that describe the external data source. This object describes the settings for the MongoDB Search and Vector Search resource to connect to an external MongoDB. Specify these settings only if you want to connect to an external MongoDB that wasn't deployed using the Kubernetes Operator. If you specify these settings, they take precedence over
spec.source.mongodbResourceRef. If you used the Kubernetes Operator to install MongoDB in the same cluster, these settings are optional.
spec.source.external.keyfileSecretRefType: object
Secret that contains the
mongodkeyfile thatmongotuses to connect to the external MongoDB deployment.
spec.source.external.keyfileSecretRef.nameType: string
Name of the Secret that contains the keyfile. You must specify this field if you set
spec.source.external.keyfileSecretRef.
spec.source.external.keyfileSecretRef.keyType: string
Key under which the keyfile is stored in the Secret. This field is optional.
Settings for Connecting to an External Replica Set
spec.source.external.hostAndPortsType: array of strings
List of hostnames and ports of the external replica set. This is a host seed list to the MongoDB replica set. The
mongotconnects to the database in a replica set mode and gets the list of all other nodes usingdb.hello().This field is mutually exclusive with
spec.source.external.shardedCluster. UsehostAndPortsfor replica set sources andshardedClusterfor sharded cluster sources.Example
hostAndPorts: - mdbc-rs-0.my-external-domain.example.com:27017 - mdbc-rs-1.my-external-domain.example.com:27017 - mdbc-rs-2.my-external-domain.example.com:27017
spec.source.external.tlsType: object
TLS Settings that
mongotmust use when connecting to the external MongoDB database.
spec.source.external.tls.ca.nameType: string
Name of the ConfigMap containing the trusted chain of the certificate authorities that issued the TLS certificate used by the
mongodnodes.Example
spec: source: external: tls: ca: name: trusted-ca You must specify the certificate (or certificate chain) under the
ca.crtkey in this ConfigMap.Example
kind: ConfigMap apiVersion: v1 metadata: name: trusted-ca data: ca.crt: | -----BEGIN CERTIFICATE----- MIIDBTCCAe2gAwIBAgIIH3EOUAGAsx0wDQYJKoZIhvcNAQELBQAwFTETMBEGA1UE [...] U/4rN8Ias/FONYFRtGfs9uXHmo2MP04BF+9ED2dlbNDUbat+6XCozLJj98nI4VEi qaV3JrVFHTgN -----END CERTIFICATE-----
Settings for Connecting to an External Sharded Cluster
The following settings are required only for configuring a connection to an external MongoDB sharded cluster. They extend the existing spec.source.external settings.
Note
spec.source.external.hostAndPorts (for replica sets) and spec.source.external.shardedCluster are mutually exclusive. Specify only one of them.
spec.source.external.shardedClusterType: object
Declares an external sharded MongoDB cluster as the data source for
mongot. Contains configuration formongosrouters and per-shard replica set members.Use this only if the MongoDB sharded cluster is deployed outside of Kubernetes and is not managed by the Kubernetes Operator. For operator-managed sharded clusters deployed with the
MongoDBCRD, usespec.source.mongodbResourceRefinstead. The Kubernetes Operator auto-discovers shard topology.Example
spec: source: external: shardedCluster: router: hosts: - "mongos1.external:27017" - "mongos2.external:27017" shards: - shardName: "shard-0" hosts: - "shard0-node1.external:27018" - "shard0-node2.external:27018" - shardName: "shard-1" hosts: - "shard1-node1.external:27018" - "shard1-node2.external:27018"
spec.source.external.shardedCluster.routerType: object
Configuration for the
mongos(router) instances of the external sharded cluster.
spec.source.external.shardedCluster.router.hostsType: array of strings
List of endpoints for the
mongosrouter instances inhost:portformat. Allmongotinstances connect to these routers. Specify at least one entry.Example
router: hosts: - "mongos1.external:27017" - "mongos2.external:27017"
spec.source.external.shardedCluster.shardsType: array of objects
List of all shards in the external MongoDB cluster. Each entry describes one shard's replica set. The Kubernetes Operator creates one
mongotStatefulSet for each shard, where each StatefulSet contains the number of pods specified inspec.clusters[].replicas. Specify at least one shard entry.
spec.source.external.shardedCluster.shards[*].shardNameType: string
The logical name of the shard. The Kubernetes Operator uses this name for Kubernetes resource naming (StatefulSets, Services, Secrets). The value can be different from the MongoDB shard name.
Naming constraints:
Must be unique across all shards.
Must conform to Kubernetes DNS label name rules (RFC 1123), which allow lowercase alphanumeric characters and hyphens (
-), and require that the name start and end with an alphanumeric character. Periods (.) and underscores (_) are not allowed. The maximum length is 63 characters.The Kubernetes Operator combines
metadata.name, the cluster index, andshardNameinto the names of the Kubernetes resources it creates (for example,{name}-search-{clusterIndex}-{shardName}), and validates that every generated name fits within the Kubernetes DNS limits of 63 characters for labels and 253 characters for subdomain names. KeepshardNameshort enough for these limits.
Example
shards: - shardName: "shard-0" hosts: - "shard0-node1.external:27018"
spec.source.external.shardedCluster.shards[*].hostsType: array of strings
List of endpoints of the
mongodreplica set members for this shard in thehost:portformat.mongotinstances replicate data from these hosts. Specify at least one entry.Each replica set (shard) has its own group of
mongotinstances, which source data only from that replica set. Different shards never share the samemongotinstances.Example
shards: - shardName: "shard-0" hosts: - "shard0-node1.external:27018" - "shard0-node2.external:27018" - "shard0-node3.external:27018"
Settings for Cluster Deployment
The following settings describe each entry of the required spec.clusters array.
spec.clustersType: array of objects
Per-Kubernetes-cluster deployment configuration for MongoDBSearch. This field is required and must contain at least one entry and at most 50 entries. All sizing and placement settings, such as
replicas,loadBalancer,resourceRequirements,persistence,jvmFlags, andstatefulSet, live inside aclustersentry. These settings have no top-level equivalents.For a single-cluster deployment, specify one entry. You can omit
nameandindex.Example
spec: clusters: - {} For a multi-cluster deployment, specify one entry for each Kubernetes cluster that runs
mongotpods. If you specify more than one entry, the following rules apply:nameis required on every entry and must be unique.indexis required on every entry and must be unique.The MongoDB source must be external (
spec.source.external). Multi-cluster deployments don't support operator-managed MongoDB sources.Every entry must configure an operator-managed load balancer (
loadBalancer.managed). Multi-cluster deployments don't support unmanaged load balancers.
The Kubernetes Operator enforces these rules through CRD validation rules and reconcile-time validation.
spec.clusters[].nameType: string
Name of the Kubernetes cluster for this entry, with a maximum length of 253 characters. You can omit this field for a single-cluster deployment.
If
spec.clusterscontains more than one entry,nameis required, must be unique across entries, and can't change after you create the resource.
spec.clusters[].indexType: integer
Stable integer identifier of the Kubernetes cluster for this entry. The value must be between
0and999, and must be unique across entries. Ifspec.clusterscontains more than one entry,indexis required on every entry.The Kubernetes Operator includes the index in the names of the Kubernetes resources it creates for this cluster entry, for example
{name}-search-{index}for StatefulSets,{name}-search-{index}-svcfor Services, and{name}-search-{index}-configfor ConfigMaps. For sharded cluster sources, the names also include the shard name, for example{name}-search-{index}-{shardName}and{name}-search-{index}-{shardName}-svc.Warning
Don't change the
indexof an existing entry because the index is part of the resource names. Changing it causes the Kubernetes Operator to create new resources under the new index and orphan the resources at the old index. This applies to every index-bearing resource, including proxy Services ({name}-search-{index}[-{shardName}]-proxy-svc), the Envoy Deployment and ConfigMap ({name}-search-lb-{index}), load balancer certificate Secrets, and metrics forwarder resources ({name}-search-metrics-forwarder-{index}).For a single-cluster deployment, you can omit this field and it defaults to
0. However, if each member Kubernetes cluster runs its own Kubernetes Operator instance, setindexexplicitly to a distinct value in each cluster's MongoDBSearch resource. Distinct indexes keep the generated hostnames and resource names from colliding across clusters.
Sizing and Storage
spec.clusters[].replicasType: integer
Number of
mongotpods to deploy in this Kubernetes cluster. For a replica set source, this is the total number ofmongotpods. For a sharded cluster source, this is the number ofmongotpods per shard.If
spec.clusters[].replicasis greater than1, you must also configurespec.clusters[].loadBalancerto route traffic betweenmongodand the multiplemongotinstances.If you set
spec.clusters[].replicasto0, the Kubernetes Operator takes themongotdeployment in this cluster offline. The Kubernetes Operator scales the StatefulSet to zero pods and keeps the MongoDBSearch resource and its other Kubernetes resources in place.If omitted, defaults to
1.Example
spec: clusters: - replicas: 2
spec.clusters[].resourceRequirementsType: core/v1/ResourceRequirements
CPU and memory that the
mongodb-searchcontainer can request and be limited to. We recommend using this field to customize resource allocations instead of overriding it withspec.clusters[].statefulSet.If you do not override the JVM heap size in
spec.clusters[].jvmFlags, the Kubernetes Operator sets the default heap size (-Xmx) to 50% of the memory request of themongotcontainer. Adjustspec.clusters[].resourceRequirementsaccordingly to control both pod resources and JVM heap size.If omitted, the Kubernetes Operator uses the following default values:
requests: cpu: 2 memory: 4Gi
spec.clusters[].resourceRequirements.limitsType: object
Upper cap on the resources (CPU and memory) that the
mongodb-searchcontainer can consume. By default, no limits are set. If omitted, the pod isn't restricted and so, might use all the resources on the node. We recommend setting limits based on your workload.
spec.clusters[].resourceRequirements.requestsType: object
Amount of CPU and memory requested for the
mongodb-searchcontainer. If you specify only one ofcpuormemory, the Kubernetes Operator applies the default value for the other. If omitted, the Kubernetes Operator uses the following default values:requests: cpu: 2 memory: 4Gi
spec.clusters[].persistence.singleType: object
Storage configuration for MongoDB Search and Vector Search persistence volume where MongoDB Search and Vector Search indexes are stored. Each search instance (pod) has its own independent storage to maintain indexes, which isn't shared with the MongoDB database. Only index metadata (definitions) are stored in the database itself.
ScalarData TypeDescriptionlabelSelectorstring
Tag used to bind mounted volumes to directories.
storagestring
Minimum size of Persistent Volume to mount. This value is expressed as an integer followed by a unit of storage in JEDEC notation.
Default value is
16G.For example, if a replica set requires 60 gigabytes of storage space, set this value to
60G.storageClassstring
Type of storage specified in a Persistent Volume Claim. You can create this storage type as a StorageClass object before using it in this object specification.
Make sure to set the StorageClass
reclaimPolicyto Retain. This ensures that data is retained when a Persistent Volume Claim is removed.MongoDBSearch supports only the
singlepersistence mode, which uses one volume for all data. Although the CRD schema also contains aspec.clusters[].persistence.multiplefield, the Kubernetes Operator doesn't apply it. If you omitpersistence, the Kubernetes Operator setsspec.clusters[].persistence.single.storageto16G.
Load Balancing
spec.clusters[].loadBalancerType: object
Configuration for L7 load balancing between
mongod(ormongos) andmongot. This field is required ifspec.clusters[].replicasis greater than1. Ifspec.clusters[].replicasis1, this field is optional. You can configure a load balancer even for a singlemongotinstance to prepare for scaling up later.Exactly one of
managedorunmanagedmust be set.All entries in
spec.clustersmust agree on the load balancer mode: either every entry setsloadBalancer.managed, every entry setsloadBalancer.unmanaged, or no entry setsloadBalancer. The Kubernetes Operator rejects mixed modes. Multi-cluster deployments support only the managed mode.The load balancer affects which TLS certificates
mongodclients see and which hostnames those certificates must contain:Without a load balancer,
mongodconnects directly tomongot. The TLS certificate presented tomongodismongot's own certificate. If the MongoDB cluster is outside of Kubernetes, themongotservice is exposed on an external domain. You must include that external domain in themongotTLS certificate's SAN (Subject Alternative Name) field.With a managed load balancer (
spec.clusters[].loadBalancer.managed), the Envoy proxy is the only component that connects directly tomongot. The Envoy proxy reachesmongotthrough the internal Service FQDNs:Replica set:
<name>-search-<clusterIndex>-svc.<ns>.svc.cluster.localSharded cluster:
<name>-search-<clusterIndex>-<shard>-svc.<ns>.svc.cluster.local
We recommend that you include these service FQDNs in the
mongotTLS certificate's SAN field. The operator-managed Envoy proxy currently validates themongotcertificate against the certificate authority only and doesn't match SAN hostnames. Externalmongodprocesses see the Envoy proxy's TLS certificate, so include external domains in the Envoy certificate's SANs, not in themongotcertificate.
Tip
Enable a managed load balancer even if you initially deploy a single
mongotpod. With the load balancer in place, the domains in your TLS certificates remain stable if you scale upspec.clusters[].replicaslater because the load balancer is already present betweenmongodandmongot.
spec.clusters[].loadBalancer.managedType: object
Configures an operator-managed Envoy load balancer. The Kubernetes Operator deploys and manages the Envoy proxy with correct routing, mTLS, and HTTP/2+gRPC stream pinning. Set this field to an empty object (
{}) to use the defaults.This field is mutually exclusive with
spec.clusters[].loadBalancer.unmanaged.For sharded cluster sources, you must also configure
spec.security.tlsif you use a managed load balancer. The Envoy proxy routes traffic to the correct shard using SNI, which requires TLS.Example
spec: clusters: - loadBalancer: managed: {}
spec.clusters[].loadBalancer.managed.externalHostnameType: string
Hostname that the Envoy proxy expects for SNI matching on incoming requests. The Kubernetes Operator uses this value to configure routing rules that match the TLS SNI field from incoming
mongodconnections. The Envoy TLS server certificate must include this hostname in its SAN (Subject Alternative Name) field.For sharded cluster sources, the value must contain a
{shardName}placeholder, which the Kubernetes Operator expands per shard. Each shard gets its own hostname, and the Envoy TLS server certificate must include all expanded shard hostnames in its SANs. You can use a wildcard certificate to cover all shards with a single certificate and avoid re-issuing when shards are added. For replica set sources, don't use the{shardName}placeholder.This field is required if MongoDB is externally managed (not deployed by the Kubernetes Operator). If MongoDB is operator-managed in the same cluster, omit this field because the Kubernetes Operator auto-configures routing.
In multi-cluster deployments, each cluster entry typically uses a distinct hostname. However, the Kubernetes Operator permits sharing one hostname across clusters, for example if a failover proxy that spans availability zones fronts the Envoy proxies of multiple clusters.
Example
# Replica set with external MongoDB spec: clusters: - loadBalancer: managed: externalHostname: "search.apps.example.com" # Sharded cluster with external MongoDB spec: clusters: - loadBalancer: managed: externalHostname: "{shardName}.search.example.com"
spec.clusters[].loadBalancer.managed.routerHostnameType: string
Endpoint that
mongosrouters use to reach this cluster'smongotinstances through the managed Envoy load balancer, in thehost:portformat. The Kubernetes Operator uses the hostname for SNI matching on the cluster-level routing chain, so the Envoy TLS server certificate must include this hostname in its SANs.This field is required if you use a managed load balancer with an external sharded MongoDB source (
spec.source.external.shardedCluster). The Kubernetes Operator ignores this field for replica set sources and for operator-managed MongoDB.Unlike
externalHostname, the Kubernetes Operator uses this value verbatim, so the value must not contain a{shardName}placeholder. This endpoint is the shard-agnostic entry point formongos.In multi-cluster deployments, each cluster entry typically uses a distinct value. However, the Kubernetes Operator permits sharing one value across clusters, for example if a failover proxy that spans availability zones fronts the Envoy proxies of multiple clusters.
Example
spec: clusters: - loadBalancer: managed: externalHostname: "{shardName}.search.example.com" routerHostname: "search-router.example.com:27028"
spec.clusters[].loadBalancer.managed.replicasType: integer
Number of Envoy proxy pods to deploy in this Kubernetes cluster. The value must be
1or greater. If omitted, defaults to1.
spec.clusters[].loadBalancer.managed.resourceRequirementsType: core/v1/ResourceRequirements
CPU and memory that the Envoy container can request and be limited to. If you specify this setting, the Kubernetes Operator replaces the defaults entirely.
If omitted, the Kubernetes Operator uses the following default values:
requests: cpu: 100m memory: 128Mi limits: cpu: 500m memory: 512Mi Example
spec: clusters: - loadBalancer: managed: resourceRequirements: requests: cpu: "200m" memory: "256Mi" limits: cpu: "1" memory: "1Gi"
spec.clusters[].loadBalancer.managed.deploymentType: object
Overrides that the Kubernetes Operator merges into the operator-created Envoy Deployment. Follows the same convention as
spec.statefulSeton MongoDB resources. If omitted, the Kubernetes Operator uses defaults for the Envoy Deployment.This object contains two fields:
metadata— containslabelsandannotationsfields that the Kubernetes Operator merges into the Envoy Deployment metadata.spec— an apps/v1/DeploymentSpec object. The Kubernetes Operator merges these overrides into the Envoy Deployment spec.
Example
spec: clusters: - loadBalancer: managed: deployment: spec: template: spec: nodeSelector: kubernetes.io/os: linux
spec.clusters[].loadBalancer.managed.retryPolicyType: object
Retry behavior that the Envoy proxy applies to individual gRPC streams to the upstream
mongotinstances. The Envoy proxy sends each retry attempt to a differentmongothost than the failed attempt.If you omit this field, the Envoy proxy retries with the default values:
2retries with a per-try timeout of60s.Example
spec: clusters: - loadBalancer: managed: retryPolicy: numRetries: 2 perTryTimeout: "60s"
spec.clusters[].loadBalancer.managed.retryPolicy.numRetriesType: integer
Maximum number of retries per request. The value must be
1or greater. If omitted, defaults to2, which allows three total attempts for each request.
spec.clusters[].loadBalancer.managed.retryPolicy.perTryTimeoutType: string
Timeout for each individual attempt, including the original request, expressed as a duration string (for example,
"30s"). If omitted, defaults to"60s".
spec.clusters[].loadBalancer.managed.minMongotReadyReplicasType: integer
Minimum number of ready
mongotreplicas that amongotgroup (for example, themongotinstances of one shard) must have before the Envoy proxy routes traffic to it. While a group is below this threshold, the Envoy proxy forwards the traffic intended for that group to a healthymongotgroup and marks the requests with therouted_from_another_shardheader. These requests return empty results instead of errors.The value must be
1or greater. If omitted, defaults to1.
spec.clusters[].loadBalancer.unmanagedType: object
Configures a user-provided (Bring Your Own) L7 load balancer. You are responsible for deploying and configuring the load balancer externally.
This field is mutually exclusive with
spec.clusters[].loadBalancer.managed. Multi-cluster deployments don't support unmanaged load balancers.
spec.clusters[].loadBalancer.unmanaged.endpointType: string
The endpoint of the BYO load balancer in
host:portformat. You must specify this field if you configurespec.clusters[].loadBalancer.unmanaged.If the Kubernetes Operator manages the MongoDB deployment (using
spec.source.mongodbResourceRef), the Kubernetes Operator writes this value into themongodconfiguration asmongotHostandsearchIndexManagementHostAndPort. If MongoDB is external, you configure themongodparameters yourself using the same value.For external sharded cluster sources, the value must contain a
{shardName}placeholder that the Kubernetes Operator expands per shard, and it must contain more than just the placeholder. For external replica set sources, the value must not contain a{shardName}placeholder.Example
# Replica set example spec: clusters: - loadBalancer: unmanaged: endpoint: "search-lb.corp.example.com:443" # Sharded cluster example spec: clusters: - loadBalancer: unmanaged: endpoint: "{shardName}-lb.corp.example.com:443"
Per-Shard Overrides
spec.clusters[].shardOverridesType: array of objects
Overrides that size specific shards within this cluster entry differently from the cluster defaults. Use this field to give individual shards more or fewer
mongotreplicas, resources, or storage than the rest of the cluster.You can use this field only with an external sharded cluster source (
spec.source.external.shardedCluster). Each shard name that you reference must exist inspec.source.external.shardedCluster.shards[*].shardName, and you can override each shard at most once per cluster entry.If you set
replicas,resourceRequirements,persistence, orjvmFlagsin an override, they replace the cluster value for the named shards. The Kubernetes Operator deep-mergesstatefulSetonto the cluster value. Fields that you don't set inherit the cluster value.Example
spec: clusters: - replicas: 2 shardOverrides: - shardNames: - shard-0 replicas: 3 resourceRequirements: requests: cpu: "4" memory: 8Gi
spec.clusters[].shardOverrides[*].shardNamesType: array of strings
Names of the shards within this cluster entry that the override applies to. This field is required and must contain at least one entry.
spec.clusters[].shardOverrides[*].replicasType: integer
Replaces the cluster's
mongotreplica count for the named shards. A value of0takes themongotinstances for these shards offline.
spec.clusters[].shardOverrides[*].resourceRequirementsType: core/v1/ResourceRequirements
Replaces the cluster's CPU and memory requests and limits for the named shards.
spec.clusters[].shardOverrides[*].persistenceType: object
Replaces the cluster's persistent volume configuration for the named shards. Uses the same schema as
spec.clusters[].persistence.
spec.clusters[].shardOverrides[*].statefulSetType: object
StatefulSet overrides for the named shards. Unlike the other override fields, the Kubernetes Operator deep-merges this value onto the cluster's
spec.clusters[].statefulSetvalue instead of replacing it.
spec.clusters[].shardOverrides[*].jvmFlagsType: array of strings
Replaces the cluster's
spec.clusters[].jvmFlagsfor the named shards if you set it to a non-empty list. The format rules forspec.clusters[].jvmFlagsalso apply to this field.
Sync Source Selection
spec.clusters[].syncSourceSelectorType: object
Selects which
mongodnodes themongotinstances in this cluster entry sync data from.
spec.clusters[].syncSourceSelector.matchTagSetsType: array of objects
Ordered list of replica set tag sets that selects the sync source
mongodnodes by their replica set tags. The Kubernetes Operator passes the list to themongotconfiguration.mongotsyncs from the nodes that the first matching tag set selects, and prefers secondary nodes.Each entry is a map of tag names to tag values. An empty document (
{}) matches any node, so you can append a trailing{}entry as a match-any fallback if no earlier tag set matches. You can specify at most 50 entries.Example
spec: clusters: - syncSourceSelector: matchTagSets: - region: us-east-1 workload: search - {}
JVM Flags
spec.clusters[].jvmFlagsType: array of strings
JVM flags passed to the
mongotprocess. The Kubernetes Operator includes the flags without modification in themongotstartup command using--jvm-flags "<all flags space-separated>".Each flag must start with
-X,-XX:, or-D, must not contain spaces, and can contain only alphanumeric characters and the.,_,+,:,-, and=characters. The Kubernetes Operator rejects flags that don't match these rules.If you don't specify
-Xmsor-Xmxin this field, the Kubernetes Operator auto-calculates heap size by setting both to half ofspec.clusters[].resourceRequirements.requests.memory. If you don't specify resource requirements, the Kubernetes Operator uses a default of 4Gi memory request, yielding approximately-Xmx2048m -Xms2048m.If you provide your own
-Xmsor-Xmxvalues, the Kubernetes Operator uses them and does not override the values. The Kubernetes Operator always appends the flags you provide after the operator-computed flags.To learn more, see Hardware Sizing for mongot.
Example
spec: clusters: - jvmFlags: - -Xms2g - -Xmx2g
StatefulSet Overrides
spec.clusters[].statefulSetType: object
Overrides for the StatefulSet that the Kubernetes Operator creates for deploying
mongotpods. The Kubernetes Operator always applies the overrides last, so they overwrite the settings that the Kubernetes Operator computes.This object contains two fields:
metadata— containslabelsandannotationsfields that the Kubernetes Operator merges into the StatefulSet metadata.spec— an apps/v1/StatefulSetSpec object. The Kubernetes Operator merges these overrides into the StatefulSet spec.
Note
Don't set resource requirements or persistence settings using
spec.clusters[].statefulSet. Instead, use thespec.clusters[].resourceRequirementsandspec.clusters[].persistencefields respectively.
Advanced mongot Settings
spec.clusters[].advancedMongotConfigsType: object
Advanced
mongotsettings for this cluster entry. The Kubernetes Operator renders the value verbatim under theadvancedConfigskey of themongotconfiguration file, without reading or modifying it. This field doesn't affect the settings that the Kubernetes Operator generates elsewhere in themongotconfiguration.Use this field only for
mongotsettings that the MongoDBSearch resource doesn't expose as first-class fields.
Settings for Security
spec.securityType: object
Security settings for
mongotlisten server.
spec.security.tlsType: object
TLS settings for
mongot. If omitted,mongotdoesn't use TLS for incoming connections.If you use a managed load balancer with a sharded cluster source, this field is required. The Envoy proxy routes traffic to the correct shard using SNI, which depends on the TLS ClientHello. The Kubernetes Operator fails the reconcile if you omit
spec.security.tlsin this configuration.
spec.security.tls.certificateKeySecretRef.nameType: string
Deprecated since version 1.8.0. : Use
spec.security.tls.certsSecretPrefixinstead.Name of the TLS secret in the same namespace containing the private key (
tls.key) and the certificate (tls.crt). The secret can be of typekubernetes.io/tls(that is issued by cert-manager) or can be created manually.The Kubernetes Operator still supports this field for replica set deployments for backwards compatibility. However:
For sharded cluster deployments, the Kubernetes Operator rejects this field during validation. Use
spec.security.tls.certsSecretPrefixinstead, because a single secret reference cannot cover per-shard certificates.If you specify both
certificateKeySecretRefandcertsSecretPrefix,certificateKeySecretReftakes precedence for replica set deployments.
For new deployments, use
spec.security.tls.certsSecretPrefixeven for replica sets.
spec.security.tls.certsSecretPrefixType: string
Prefix that the Kubernetes Operator uses to derive TLS secret names by naming convention. If you set this field, the Kubernetes Operator looks for secrets following these patterns instead of requiring explicit secret references for each component:
ComponentSecret Name PatternReplica set's
mongotserver cert{certsSecretPrefix}-{name}-search-certSharded
mongotcert (per cluster and shard){certsSecretPrefix}-{name}-search-{clusterIndex}-{shardName}-certManaged load balancer server cert (per cluster, all topologies)
{certsSecretPrefix}-{name}-search-lb-{clusterIndex}-certManaged load balancer client cert
{certsSecretPrefix}-{name}-search-lb-{clusterIndex}-client-certWhere:
{name}ismetadata.nameof the MongoDBSearch resource{clusterIndex}is the value ofspec.clusters[].index(0for a single-cluster deployment that doesn't set an index){shardName}is the value ofspec.source.external.shardedCluster.shards[*].shardName
The Kubernetes Operator uses one managed load balancer server certificate per cluster for all topologies. For sharded clusters, the SANs of this certificate must include all expanded shard hostnames from
externalHostnameand therouterHostname.The Kubernetes Operator resolves the
mongotserver certificate secret name in the following order:If you set
spec.security.tls.certificateKeySecretRef.name, the Kubernetes Operator uses that name.If you set
certsSecretPrefix, the Kubernetes Operator uses the naming patterns in the preceding table.If you set neither field, the Kubernetes Operator uses the default name
{name}-search-certfor replica set deployments, or the default per-shard pattern{name}-search-{clusterIndex}-{shardName}-certfor sharded deployments.
If you don't set
certsSecretPrefix, the managed load balancer certificates also use default names: the Kubernetes Operator mounts{name}-search-lb-{clusterIndex}-certfor the server certificate and{name}-search-lb-{clusterIndex}-client-certfor the client certificate.Note
For sharded cluster deployments, the Kubernetes Operator rejects
certificateKeySecretRefbecause a single secret reference cannot cover per-shard certificates. UsecertsSecretPrefix, or set neither field and create secrets that follow the default per-shard pattern and the default-named load balancer certificate secrets.Example
spec: security: tls: certsSecretPrefix: my-prefix
spec.security.tls.keyFilePasswordSecretRefType: object
Secret that contains the password that decrypts the password-encrypted server private key in the TLS certificate secret. The Secret must contain the password under the
keyFilePasswordkey. Omit this field if the server private key is not encrypted.
Settings for Logging
spec.logLevelType: string
Verbosity of the
mongotlogs. Value can be one of the following:TRACEDEBUGINFOWARNERROR
If omitted, defaults to
INFO.
Settings for Metrics
spec.observabilityType: object
Observability settings for the MongoDBSearch resource, including the Prometheus metrics endpoint in
mongotand the metrics forwarder for Ops Manager.
spec.observability.prometheusType: object
Configuration for the Prometheus metrics endpoint in
mongot. If you omit this field, the Kubernetes Operator enables the metrics endpoint on the default port9946. To disable the endpoint, setspec.observability.prometheus.modetodisabled. To change the port, setspec.observability.prometheus.port.
spec.observability.prometheus.modeType: string
Enables or disables the Prometheus metrics endpoint in
mongot. Value can be one of the following:enableddisabled
If omitted, defaults to
enabled.
spec.observability.prometheus.portType: integer
Port on which to enable Prometheus metrics endpoint. By default, Prometheus metrics endpoint is enabled on port
9946.
spec.observability.metricsForwarderType: object
Configuration for the metrics forwarder, a Deployment that the Kubernetes Operator creates to scrape the
mongotPrometheus metrics and forward them to Ops Manager.
spec.observability.metricsForwarder.modeType: string
Whether the Kubernetes Operator creates the metrics forwarder. Value can be one of the following:
auto— The Kubernetes Operator creates the forwarder for operator-managedMongoDB(Ops Manager-backed) sources, and for external sources only if you setspec.observability.metricsForwarder.opsManager. ForMongoDBCommunitysources, the Kubernetes Operator doesn't create the forwarder.enabled— The Kubernetes Operator always creates the forwarder. If the source is aMongoDBCommunityresource, the Kubernetes Operator reports an error because the forwarder isn't supported forMongoDBCommunitysources.disabled— The Kubernetes Operator never creates the forwarder.
If omitted, defaults to
auto.The
enabledandautomodes require the Prometheus endpoint (spec.observability.prometheus) to be enabled. If you disable the endpoint, the Kubernetes Operator reports anInvalidmetrics forwarder status.
spec.observability.metricsForwarder.resourceRequirementsType: core/v1/ResourceRequirements
CPU and memory that the metrics forwarder container can request and be limited to.
If omitted, the Kubernetes Operator uses the following default values:
requests: cpu: 100m memory: 128Mi limits: cpu: 250m memory: 256Mi
spec.observability.metricsForwarder.deploymentType: object
Overrides that the Kubernetes Operator merges into the operator-created metrics forwarder Deployment. Follows the same convention as
spec.clusters[].loadBalancer.managed.deployment: ametadatafield withlabelsandannotations, and aspecfield with an apps/v1/DeploymentSpec object.
spec.observability.metricsForwarder.opsManagerType: object
Ops Manager project and credentials that the metrics forwarder sends metrics to. If omitted, the Kubernetes Operator derives the project and credentials from the connection configuration of the source MongoDB resource. Set this field for external MongoDB sources, where no source MongoDB resource exists.
If you set this field, you must set both
agentCredentialsandprojectConfigMapRef.
spec.observability.metricsForwarder.opsManager.agentCredentials.nameType: string
Name of the Secret that contains the Ops Manager Agent API key that the metrics forwarder authenticates with.
spec.observability.metricsForwarder.opsManager.projectConfigMapRef.nameType: string
Name of the ConfigMap that contains the Ops Manager project configuration that the metrics forwarder sends metrics to.
Settings for Automated Embedding
Important
Automated embedding is available only as a Preview feature for MongoDB Community Edition deployment. The feature and corresponding documentation might change at any time during the Preview period. To learn more, see Preview Features.
spec.autoEmbeddingType: Object
Configuration for Automated Embedding for text data in your collection.
spec.autoEmbedding.embeddingModelAPIKeySecretType: Object
Configuration for the embedding model provider API keys. To enable Automated Embedding, you must create two keys, one for generating embeddings at index-time for data in your collection and another for generating embeddings at query-time for the query text. If you don't already have the keys, we recommend that you create keys from two Atlas projects. To learn more about creating keys for the Atlas projects from the Atlas UI, see Manage API Keys.
spec.autoEmbedding.embeddingModelAPIKeySecret.nameType: string
Name of the secret that contains the embedding model API keys that
mongotmust use to generate embeddings at index- and query-time. The Secret must contain the index-time key under theindexing-keykey and the query-time key under thequery-keykey.You can omit
embeddingModelAPIKeySecretonly ifspec.autoEmbedding.providerEndpointpoints to the operator-managed, self-hosted Voyage AI embedding service. Otherwise, the Kubernetes Operator requires it.
spec.autoEmbedding.providerEndpointType: string
Embedding model endpoint URL for generating embeddings. Value varies based on whether you create the keys from the Atlas UI (recommended) or directly from the embedding service (Voyage AI). For keys created from:
Atlas UI, value is
https://ai.mongodb.com/v1/embeddings(default)Voyage AI, value is
https://api.voyageai.com/v1/embeddings
Settings for Feature Flags
spec.featureFlagsType: object
Feature flags for
mongot. If you set a flag totrue, the Kubernetes Operator renders it into themongotconfiguration. If you omit thefeatureFlagsobject or an individual flag, the schema default for that flag applies (trueforenableOverloadRetrySignal).
spec.featureFlags.enableOverloadRetrySignalType: boolean
Enables the
mongotoverload retry signal. If you enable this flag,mongotsignals load shedding to upstream proxies (such as the operator-managed Envoy load balancer) through gRPCRESOURCE_EXHAUSTEDresponses. The proxies then retry the request on anothermongotinstance.If omitted, defaults to
true.
Other Settings
spec.versionType: string
Version of the
mongodb-searchDocker image. If omitted, the Kubernetes Operator uses the default MongoDB Search version bundled with it. You can set the version explicitly to prevent automatic upgrades when you upgrade the Kubernetes Operator.
Status Fields
The Kubernetes Operator reports status information under the status field of the MongoDBSearch resource.
status.phaseType: string
Current phase of the MongoDBSearch resource. Possible values include
Pending,Running,Failed,Disabled,Updated, andUnsupported.This field is visible in
kubectl getoutput under thePHASEcolumn.
status.messageType: string
Human-readable message with details about the current status, such as the reason the resource is in a
PendingorFailedphase.
status.lastTransitionType: string
Timestamp of the last transition of
status.phase.
status.observedGenerationType: integer
Generation of the MongoDBSearch resource that the Kubernetes Operator last processed.
status.warningsType: array of strings
Warnings that the Kubernetes Operator reports for the resource.
status.versionType: string
Version of MongoDB Search (
mongot) that the Kubernetes Operator reconciled.This field is visible in
kubectl getoutput under theVERSIONcolumn.
status.resourcesNotReadyType: array of objects
Dependent Kubernetes resources that are not yet ready. Each entry reports the
kindandnameof the resource and an optionalmessageand list oferrors.
status.pvcType: array of objects
State of the persistent volume claims of the
mongotStatefulSets. Each entry reports thephaseand thestatefulsetNamethat the claims belong to.
status.loadBalancerType: object
Status of the operator-managed load balancer (Envoy). This field is present only if you set
spec.clusters[].loadBalancer.managed. For multi-cluster deployments, the Kubernetes Operator reports the worst phase across the Envoy deployments of all clusters.
status.loadBalancer.phaseType: string
Current phase of the managed load balancer. Possible values include
Pending,Running, andFailed. The Kubernetes Operator reports this phase independently of the mainstatus.phase, so you can monitor the Envoy deployment separately.This field is also visible in
kubectl getoutput under theLOADBALANCERcolumn.
status.loadBalancer.messageType: string
Human-readable message with details about the managed load balancer status.
status.metricsForwarderType: object
Status of the metrics forwarder.
status.metricsForwarder.phaseType: string
Current phase of the metrics forwarder. Possible values include
Pending,Running, andFailed. The phase reportsDisabledif you setspec.observability.metricsForwarder.modetodisabled.This field is also visible in
kubectl getoutput under theMETRICSFORWARDERcolumn.
status.metricsForwarder.messageType: string
Human-readable message with details about the metrics forwarder status.
Example
kubectl get mdbs NAME PHASE VERSION LOADBALANCER METRICSFORWARDER AGE mdb-rs-ext-lb-search Running 1.70.1 Running Running 14m