You can use the Kubernetes Operator to deploy MongoDB Search and
Vector Search on a Kubernetes cluster to run with an external
MongoDB Enterprise Edition v8.2.0 or higher server. This procedure
demonstrates how to deploy and configure the mongot process in your
Kubernetes cluster to use a new or existing external replica set deployment.
This tutorial demonstrates how to configure a secure deployment with
TLS enabled. You must provide provide the TLS certificates:
The server certificate and key for the MongoDBSearch service.
The public CA certificate for the external MongoDB database.
Prerequisites
To deploy MongoDB Search and Vector Search, you must have the following:
A running Kubernetes cluster with
kubeconfigavailable locally.Kubernetes command-line tool,
kubectl, configured to communicate with your cluster.Helm, the package manager for Kubernetes, to install the Kubernetes Operator.
Bash v5.1 or higher for running the commands in this tutorial.
A MongoDB Enterprise Edition replica set running version 8.2 or higher for storing data.
To learn more about deploying MongoDB Enterprise, see Deploy and Configure MongoDB Database Resources.
A running MongoDB Cloud Manager or Ops Manager for managing MongoDB tasks.
External DB TLS
Your external MongoDB Enterprise deployment must be configured to use and require TLS connections.
External DB CA file
You must have the public Certificate Authority (CA) certificate file (for example,
external-ca.crt) that was used to sign your external MongoDB deployment's server certificates. You will need this file locally.Search Service certificate files
You must have a valid TLS server certificate and private key (for example,
search-service.crt,search-service.key) for the MongoDBSearch service. This certificate must be valid for the hostname you will use to access the service (for example,mdbs-search.example.com).
Before You Begin
Before you install MongoDB Search and Vector Search using the Kubernetes Operator, you must do the following:
Configure Cloud Manager or Ops Manager Parameters for MongoDB Search and Vector Search
Configure a Cloud Manager or Ops Manager User for MongoDB Search and Vector Search
Configure Cloud Manager or Ops Manager Parameters for MongoDB Search and Vector Search
Log in to the Cloud Manager or Ops Manager UI and perform the following steps to configure Cloud Manager or Ops Manager for MongoDB Search and Vector Search.
Modify your Cloud Manager or Ops Manager deployment configuration.
Click the Modify button to open the deployment configuration editor.
Click Advanced Configuration Options under the Process Configuration section.
Click the Add Option button and select setParameter Startup Option from the dropdown.
Add the following parameters in the fields, one by one, by clicking Add after adding the name and value:
ParameterValuemongotHostYour search hostname and port. For example:
search-node1.example.com:27017.searchIndexManagementHostAndPortYour search hostname and port. For example:
search-node1.example.com:27017.skipAuthenticationToSearchIndexManagementServerfalsesearchTLSModeYour configured TLS mode. For example,
preferTLS, if themongotprocess is configured to accept TLS connections.useGrpcForSearchtrue
Configure a Cloud Manager or Ops Manager User for MongoDB Search and Vector Search
You must create a user with the searchCoordinator role. In MongoDB
versions 8.2 and later, the searchCoordinator is a built-in role. You must
create a user and assign the role to the user.
To create the user and assign the user the built-in
searchCoordinator role, complete the following steps by using either
the Cloud Manager or Ops Manager UI or the mongosh:
In mongosh, run the following commands:
Setup Your Environment
Prepare your environment for running the sample code in this tutorial in a terminal.
Required. Set the environment variables.
To set the environment variables for use in the subsequent steps in this procedure, copy the following, set the values for the environment variables, and then run the commands in your terminal:
1 export K8S_CTX="<your kubernetes context here>" 2 3 export MDB_NS="mongodb" 4 5 export MDB_VERSION="8.2.0" 6 7 export MDB_ADMIN_USER_PASSWORD="admin-user-password-CHANGE-ME" 8 export MDB_USER_PASSWORD="mdb-user-password-CHANGE-ME" 9 export MDB_SEARCH_SYNC_USER_PASSWORD="search-sync-user-password-CHANGE-ME" 10 11 export MDB_TLS_CA_SECRET_NAME="ca" 12 export MDB_SEARCH_TLS_SECRET_NAME="mdbs-search-tls" 13 14 export MDB_SEARCH_SERVICE_NAME="mdbs-search" 15 export MDB_SEARCH_HOSTNAME="mdbs-search.example.com" 16 17 # External MongoDB replica set members - REPLACE THESE VALUES with your actual external MongoDB hosts 18 # In production, replace with your actual external MongoDB replica set members 19 export MDB_EXTERNAL_HOST_0="mdbc-rs-0.mdbc-rs-svc.${MDB_NS}.svc.cluster.local:27017" 20 export MDB_EXTERNAL_HOST_1="mdbc-rs-1.mdbc-rs-svc.${MDB_NS}.svc.cluster.local:27017" 21 export MDB_EXTERNAL_HOST_2="mdbc-rs-2.mdbc-rs-svc.${MDB_NS}.svc.cluster.local:27017" 22 23 # REPLACE with your actual external MongoDB replica set name 24 export MDB_EXTERNAL_REPLICA_SET_NAME="mdbc-rs" 25 26 export OPERATOR_HELM_CHART="mongodb/mongodb-kubernetes" 27 export OPERATOR_ADDITIONAL_HELM_VALUES="" 28 29 export MDB_CONNECTION_STRING="mongodb://mdb-user:${MDB_USER_PASSWORD}@${MDB_EXTERNAL_HOST_0}/?replicaSet=${MDB_EXTERNAL_REPLICA_SET_NAME}&tls=true&tlsCAFile=/tls/ca.crt"
Note that these environment variables are only available in the current terminal session and will need to be set again in any new terminal sessions.
Conditional. Add the MongoDB Helm repository.
Helm automates the deployment and management of MongoDB instances on Kubernetes. If you have already added the Helm repository that contains the Helm chart for installing the Kubernetes Operator operator, skip this step. Otherwise, add the Helm repository.
To add, copy, paste, and run the following command:
1 helm repo add mongodb https://mongodb.github.io/helm-charts 2 helm repo update mongodb 3 helm search repo mongodb/mongodb-kubernetes
1 "mongodb" has been added to your repositories 2 Hang tight while we grab the latest from your chart repositories... 3 ...Successfully got an update from the "mongodb" chart repository 4 Update Complete. ⎈Happy Helming!⎈ 5 NAME CHART VERSION APP VERSION DESCRIPTION 6 mongodb/mongodb-kubernetes 1.6.1 MongoDB Controllers for Kubernetes translate th...
Conditional. Install the MongoDB Controllers for Kubernetes Operator.
The Kubernetes Operator watches MongoDB, MongoDBOpsManager, and
MongoDBSearch custom resources and manages the lifecycle of
your MongoDB deployments. If you already installed the MongoDB Controllers for Kubernetes Operator,
skip this step. Otherwise, install the MongoDB Controllers for Kubernetes Operator from the Helm
repository you added in the previous step.
To install the MongoDB Controllers for Kubernetes Operator in the mongodb namespace, copy, paste,
and run the following:
1 helm upgrade --install --debug --kube-context "${K8S_CTX}" \ 2 --create-namespace \ 3 --namespace="${MDB_NS}" \ 4 mongodb-kubernetes \ 5 {OPERATOR_ADDITIONAL_HELM_VALUES:+--set ${OPERATOR_ADDITIONAL_HELM_VALUES}} \ 6 "${OPERATOR_HELM_CHART}"
1 Release "mongodb-kubernetes" does not exist. Installing it now. 2 NAME: mongodb-kubernetes 3 LAST DEPLOYED: Wed Dec 17 11:23:39 2025 4 NAMESPACE: mongodb 5 STATUS: deployed 6 REVISION: 1 7 TEST SUITE: None 8 USER-SUPPLIED VALUES: 9 {} 10 11 COMPUTED VALUES: 12 agent: 13 name: mongodb-agent 14 version: 108.0.12.8846-1 15 community: 16 agent: 17 name: mongodb-agent 18 version: 108.0.2.8729-1 19 mongodb: 20 imageType: ubi8 21 name: mongodb-community-server 22 repo: quay.io/mongodb 23 registry: 24 agent: quay.io/mongodb 25 resource: 26 members: 3 27 name: mongodb-replica-set 28 tls: 29 caCertificateSecretRef: tls-ca-key-pair 30 certManager: 31 certDuration: 8760h 32 renewCertBefore: 720h 33 certificateKeySecretRef: tls-certificate 34 enabled: false 35 sampleX509User: false 36 useCertManager: true 37 useX509: false 38 version: 4.4.0 39 database: 40 name: mongodb-kubernetes-database 41 version: 1.6.1 42 initAppDb: 43 name: mongodb-kubernetes-init-appdb 44 version: 1.6.1 45 initDatabase: 46 name: mongodb-kubernetes-init-database 47 version: 1.6.1 48 initOpsManager: 49 name: mongodb-kubernetes-init-ops-manager 50 version: 1.6.1 51 managedSecurityContext: false 52 mongodb: 53 appdbAssumeOldFormat: false 54 name: mongodb-enterprise-server 55 repo: quay.io/mongodb 56 multiCluster: 57 clusterClientTimeout: 10 58 clusters: [] 59 kubeConfigSecretName: mongodb-enterprise-operator-multi-cluster-kubeconfig 60 performFailOver: true 61 operator: 62 additionalArguments: [] 63 affinity: {} 64 baseName: mongodb-kubernetes 65 createOperatorServiceAccount: true 66 createResourcesServiceAccountsAndRoles: true 67 deployment_name: mongodb-kubernetes-operator 68 enableClusterMongoDBRoles: true 69 enablePVCResize: true 70 env: prod 71 maxConcurrentReconciles: 1 72 mdbDefaultArchitecture: non-static 73 name: mongodb-kubernetes-operator 74 nodeSelector: {} 75 operator_image_name: mongodb-kubernetes 76 podSecurityContext: 77 runAsNonRoot: true 78 runAsUser: 2000 79 replicas: 1 80 resources: 81 limits: 82 cpu: 1100m 83 memory: 1Gi 84 requests: 85 cpu: 500m 86 memory: 200Mi 87 securityContext: {} 88 telemetry: 89 collection: 90 clusters: {} 91 deployments: {} 92 frequency: 1h 93 operators: {} 94 send: 95 frequency: 168h 96 tolerations: [] 97 vaultSecretBackend: 98 enabled: false 99 tlsSecretRef: "" 100 version: 1.6.1 101 watchedResources: 102 - mongodb 103 - opsmanagers 104 - mongodbusers 105 - mongodbcommunity 106 - mongodbsearch 107 webhook: 108 installClusterRole: true 109 registerConfiguration: true 110 opsManager: 111 name: mongodb-enterprise-ops-manager-ubi 112 readinessProbe: 113 name: mongodb-kubernetes-readinessprobe 114 version: 1.0.23 115 registry: 116 agent: quay.io/mongodb 117 database: quay.io/mongodb 118 imagePullSecrets: null 119 initAppDb: quay.io/mongodb 120 initDatabase: quay.io/mongodb 121 initOpsManager: quay.io/mongodb 122 operator: quay.io/mongodb 123 opsManager: quay.io/mongodb 124 pullPolicy: Always 125 readinessProbe: quay.io/mongodb 126 versionUpgradeHook: quay.io/mongodb 127 search: 128 name: mongodb-search 129 repo: quay.io/mongodb 130 version: 0.55.0 131 versionUpgradeHook: 132 name: mongodb-kubernetes-operator-version-upgrade-post-start-hook 133 version: 1.0.10 134 135 HOOKS: 136 MANIFEST: 137 --- 138 Source: mongodb-kubernetes/templates/database-roles.yaml 139 apiVersion: v1 140 kind: ServiceAccount 141 metadata: 142 name: mongodb-kubernetes-appdb 143 namespace: mongodb 144 --- 145 Source: mongodb-kubernetes/templates/database-roles.yaml 146 apiVersion: v1 147 kind: ServiceAccount 148 metadata: 149 name: mongodb-kubernetes-database-pods 150 namespace: mongodb 151 --- 152 Source: mongodb-kubernetes/templates/database-roles.yaml 153 apiVersion: v1 154 kind: ServiceAccount 155 metadata: 156 name: mongodb-kubernetes-ops-manager 157 namespace: mongodb 158 --- 159 Source: mongodb-kubernetes/templates/operator-sa.yaml 160 apiVersion: v1 161 kind: ServiceAccount 162 metadata: 163 name: mongodb-kubernetes-operator 164 namespace: mongodb 165 --- 166 Source: mongodb-kubernetes/templates/operator-roles-clustermongodbroles.yaml 167 kind: ClusterRole 168 apiVersion: rbac.authorization.k8s.io/v1 169 metadata: 170 name: mongodb-kubernetes-operator-mongodb-cluster-mongodb-role 171 rules: 172 - apiGroups: 173 - mongodb.com 174 verbs: 175 - '*' 176 resources: 177 - clustermongodbroles 178 --- 179 Source: mongodb-kubernetes/templates/operator-roles-telemetry.yaml 180 Additional ClusterRole for clusterVersionDetection 181 kind: ClusterRole 182 apiVersion: rbac.authorization.k8s.io/v1 183 metadata: 184 name: mongodb-kubernetes-operator-cluster-telemetry 185 rules: 186 Non-resource URL permissions 187 - nonResourceURLs: 188 - "/version" 189 verbs: 190 - get 191 Cluster-scoped resource permissions 192 - apiGroups: 193 - '' 194 resources: 195 - namespaces 196 resourceNames: 197 - kube-system 198 verbs: 199 - get 200 - apiGroups: 201 - '' 202 resources: 203 - nodes 204 verbs: 205 - list 206 --- 207 Source: mongodb-kubernetes/templates/operator-roles-webhook.yaml 208 kind: ClusterRole 209 apiVersion: rbac.authorization.k8s.io/v1 210 metadata: 211 name: mongodb-kubernetes-operator-mongodb-webhook-cr 212 rules: 213 - apiGroups: 214 - "admissionregistration.k8s.io" 215 resources: 216 - validatingwebhookconfigurations 217 verbs: 218 - get 219 - create 220 - update 221 - delete 222 - apiGroups: 223 - "" 224 resources: 225 - services 226 verbs: 227 - get 228 - list 229 - watch 230 - create 231 - update 232 - delete 233 --- 234 Source: mongodb-kubernetes/templates/operator-roles-clustermongodbroles.yaml 235 kind: ClusterRoleBinding 236 apiVersion: rbac.authorization.k8s.io/v1 237 metadata: 238 name: mongodb-kubernetes-operator-mongodb-cluster-mongodb-role-binding 239 roleRef: 240 apiGroup: rbac.authorization.k8s.io 241 kind: ClusterRole 242 name: mongodb-kubernetes-operator-mongodb-cluster-mongodb-role 243 subjects: 244 - kind: ServiceAccount 245 name: mongodb-kubernetes-operator 246 namespace: mongodb 247 --- 248 Source: mongodb-kubernetes/templates/operator-roles-telemetry.yaml 249 ClusterRoleBinding for clusterVersionDetection 250 kind: ClusterRoleBinding 251 apiVersion: rbac.authorization.k8s.io/v1 252 metadata: 253 name: mongodb-kubernetes-operator-mongodb-cluster-telemetry-binding 254 roleRef: 255 apiGroup: rbac.authorization.k8s.io 256 kind: ClusterRole 257 name: mongodb-kubernetes-operator-cluster-telemetry 258 subjects: 259 - kind: ServiceAccount 260 name: mongodb-kubernetes-operator 261 namespace: mongodb 262 --- 263 Source: mongodb-kubernetes/templates/operator-roles-webhook.yaml 264 kind: ClusterRoleBinding 265 apiVersion: rbac.authorization.k8s.io/v1 266 metadata: 267 name: mongodb-kubernetes-operator-mongodb-webhook-crb 268 roleRef: 269 apiGroup: rbac.authorization.k8s.io 270 kind: ClusterRole 271 name: mongodb-kubernetes-operator-mongodb-webhook-cr 272 subjects: 273 - kind: ServiceAccount 274 name: mongodb-kubernetes-operator 275 namespace: mongodb 276 --- 277 Source: mongodb-kubernetes/templates/database-roles.yaml 278 kind: Role 279 apiVersion: rbac.authorization.k8s.io/v1 280 metadata: 281 name: mongodb-kubernetes-appdb 282 namespace: mongodb 283 rules: 284 - apiGroups: 285 - '' 286 resources: 287 - secrets 288 verbs: 289 - get 290 - apiGroups: 291 - '' 292 resources: 293 - pods 294 verbs: 295 - patch 296 - delete 297 - get 298 --- 299 Source: mongodb-kubernetes/templates/operator-roles-base.yaml 300 kind: Role 301 apiVersion: rbac.authorization.k8s.io/v1 302 metadata: 303 name: mongodb-kubernetes-operator 304 namespace: mongodb 305 rules: 306 - apiGroups: 307 - '' 308 resources: 309 - services 310 verbs: 311 - get 312 - list 313 - watch 314 - create 315 - update 316 - delete 317 - apiGroups: 318 - '' 319 resources: 320 - secrets 321 - configmaps 322 verbs: 323 - get 324 - list 325 - create 326 - update 327 - delete 328 - watch 329 - apiGroups: 330 - apps 331 resources: 332 - statefulsets 333 verbs: 334 - create 335 - get 336 - list 337 - watch 338 - delete 339 - update 340 - apiGroups: 341 - '' 342 resources: 343 - pods 344 verbs: 345 - get 346 - list 347 - watch 348 - delete 349 - deletecollection 350 - apiGroups: 351 - mongodbcommunity.mongodb.com 352 resources: 353 - mongodbcommunity 354 - mongodbcommunity/status 355 - mongodbcommunity/spec 356 - mongodbcommunity/finalizers 357 verbs: 358 - '*' 359 - apiGroups: 360 - mongodb.com 361 verbs: 362 - '*' 363 resources: 364 - mongodb 365 - mongodb/finalizers 366 - mongodbusers 367 - mongodbusers/finalizers 368 - opsmanagers 369 - opsmanagers/finalizers 370 - mongodbmulticluster 371 - mongodbmulticluster/finalizers 372 - mongodbsearch 373 - mongodbsearch/finalizers 374 - mongodb/status 375 - mongodbusers/status 376 - opsmanagers/status 377 - mongodbmulticluster/status 378 - mongodbsearch/status 379 --- 380 Source: mongodb-kubernetes/templates/operator-roles-pvc-resize.yaml 381 kind: Role 382 apiVersion: rbac.authorization.k8s.io/v1 383 metadata: 384 name: mongodb-kubernetes-operator-pvc-resize 385 namespace: mongodb 386 rules: 387 - apiGroups: 388 - '' 389 resources: 390 - persistentvolumeclaims 391 verbs: 392 - get 393 - delete 394 - list 395 - watch 396 - patch 397 - update 398 --- 399 Source: mongodb-kubernetes/templates/database-roles.yaml 400 kind: RoleBinding 401 apiVersion: rbac.authorization.k8s.io/v1 402 metadata: 403 name: mongodb-kubernetes-appdb 404 namespace: mongodb 405 roleRef: 406 apiGroup: rbac.authorization.k8s.io 407 kind: Role 408 name: mongodb-kubernetes-appdb 409 subjects: 410 - kind: ServiceAccount 411 name: mongodb-kubernetes-appdb 412 namespace: mongodb 413 --- 414 Source: mongodb-kubernetes/templates/operator-roles-base.yaml 415 kind: RoleBinding 416 apiVersion: rbac.authorization.k8s.io/v1 417 metadata: 418 name: mongodb-kubernetes-operator 419 namespace: mongodb 420 roleRef: 421 apiGroup: rbac.authorization.k8s.io 422 kind: Role 423 name: mongodb-kubernetes-operator 424 subjects: 425 - kind: ServiceAccount 426 name: mongodb-kubernetes-operator 427 namespace: mongodb 428 --- 429 Source: mongodb-kubernetes/templates/operator-roles-pvc-resize.yaml 430 kind: RoleBinding 431 apiVersion: rbac.authorization.k8s.io/v1 432 metadata: 433 name: mongodb-kubernetes-operator-pvc-resize-binding 434 namespace: mongodb 435 roleRef: 436 apiGroup: rbac.authorization.k8s.io 437 kind: Role 438 name: mongodb-kubernetes-operator-pvc-resize 439 subjects: 440 - kind: ServiceAccount 441 name: mongodb-kubernetes-operator 442 namespace: mongodb 443 --- 444 Source: mongodb-kubernetes/templates/operator.yaml 445 apiVersion: apps/v1 446 kind: Deployment 447 metadata: 448 name: mongodb-kubernetes-operator 449 namespace: mongodb 450 spec: 451 replicas: 1 452 selector: 453 matchLabels: 454 app.kubernetes.io/component: controller 455 app.kubernetes.io/name: mongodb-kubernetes-operator 456 app.kubernetes.io/instance: mongodb-kubernetes-operator 457 template: 458 metadata: 459 labels: 460 app.kubernetes.io/component: controller 461 app.kubernetes.io/name: mongodb-kubernetes-operator 462 app.kubernetes.io/instance: mongodb-kubernetes-operator 463 spec: 464 serviceAccountName: mongodb-kubernetes-operator 465 securityContext: 466 runAsNonRoot: true 467 runAsUser: 2000 468 containers: 469 - name: mongodb-kubernetes-operator 470 image: "quay.io/mongodb/mongodb-kubernetes:1.6.1" 471 imagePullPolicy: Always 472 args: 473 - -watch-resource=mongodb 474 - -watch-resource=opsmanagers 475 - -watch-resource=mongodbusers 476 - -watch-resource=mongodbcommunity 477 - -watch-resource=mongodbsearch 478 - -watch-resource=clustermongodbroles 479 command: 480 - /usr/local/bin/mongodb-kubernetes-operator 481 resources: 482 limits: 483 cpu: 1100m 484 memory: 1Gi 485 requests: 486 cpu: 500m 487 memory: 200Mi 488 env: 489 - name: OPERATOR_ENV 490 value: prod 491 - name: MDB_DEFAULT_ARCHITECTURE 492 value: non-static 493 - name: NAMESPACE 494 valueFrom: 495 fieldRef: 496 fieldPath: metadata.namespace 497 - name: WATCH_NAMESPACE 498 valueFrom: 499 fieldRef: 500 fieldPath: metadata.namespace 501 - name: MDB_OPERATOR_TELEMETRY_COLLECTION_FREQUENCY 502 value: "1h" 503 - name: MDB_OPERATOR_TELEMETRY_SEND_FREQUENCY 504 value: "168h" 505 - name: CLUSTER_CLIENT_TIMEOUT 506 value: "10" 507 - name: IMAGE_PULL_POLICY 508 value: Always 509 # Database 510 - name: MONGODB_ENTERPRISE_DATABASE_IMAGE 511 value: quay.io/mongodb/mongodb-kubernetes-database 512 - name: INIT_DATABASE_IMAGE_REPOSITORY 513 value: quay.io/mongodb/mongodb-kubernetes-init-database 514 - name: INIT_DATABASE_VERSION 515 value: "1.6.1" 516 - name: DATABASE_VERSION 517 value: "1.6.1" 518 # Ops Manager 519 - name: OPS_MANAGER_IMAGE_REPOSITORY 520 value: quay.io/mongodb/mongodb-enterprise-ops-manager-ubi 521 - name: INIT_OPS_MANAGER_IMAGE_REPOSITORY 522 value: quay.io/mongodb/mongodb-kubernetes-init-ops-manager 523 - name: INIT_OPS_MANAGER_VERSION 524 value: "1.6.1" 525 # AppDB 526 - name: INIT_APPDB_IMAGE_REPOSITORY 527 value: quay.io/mongodb/mongodb-kubernetes-init-appdb 528 - name: INIT_APPDB_VERSION 529 value: "1.6.1" 530 - name: OPS_MANAGER_IMAGE_PULL_POLICY 531 value: Always 532 - name: AGENT_IMAGE 533 value: "quay.io/mongodb/mongodb-agent:108.0.12.8846-1" 534 - name: MDB_AGENT_IMAGE_REPOSITORY 535 value: "quay.io/mongodb/mongodb-agent" 536 - name: MONGODB_IMAGE 537 value: mongodb-enterprise-server 538 - name: MONGODB_REPO_URL 539 value: quay.io/mongodb 540 - name: PERFORM_FAILOVER 541 value: 'true' 542 - name: MDB_MAX_CONCURRENT_RECONCILES 543 value: "1" 544 - name: POD_NAME 545 valueFrom: 546 fieldRef: 547 fieldPath: metadata.name 548 - name: OPERATOR_NAME 549 value: mongodb-kubernetes-operator 550 # Community Env Vars Start 551 - name: MDB_COMMUNITY_AGENT_IMAGE 552 value: "quay.io/mongodb/mongodb-agent:108.0.2.8729-1" 553 - name: VERSION_UPGRADE_HOOK_IMAGE 554 value: "quay.io/mongodb/mongodb-kubernetes-operator-version-upgrade-post-start-hook:1.0.10" 555 - name: READINESS_PROBE_IMAGE 556 value: "quay.io/mongodb/mongodb-kubernetes-readinessprobe:1.0.23" 557 - name: MDB_COMMUNITY_IMAGE 558 value: "mongodb-community-server" 559 - name: MDB_COMMUNITY_REPO_URL 560 value: "quay.io/mongodb" 561 - name: MDB_COMMUNITY_IMAGE_TYPE 562 value: "ubi8" 563 # Community Env Vars End 564 - name: MDB_SEARCH_REPO_URL 565 value: "quay.io/mongodb" 566 - name: MDB_SEARCH_NAME 567 value: "mongodb-search" 568 - name: MDB_SEARCH_VERSION 569 value: "0.55.0"
The preceding command installs Kubernetes Operator in the mongodb
namespace, which it creates if it doesn't already exist. After
installation, the Kubernetes Operator watches for MongoDBSearch
custom resources and manage the lifecycle of your MongoDB Search and
Vector Search deployments.
Install MongoDB Search and Vector Search
Required. Create and load the MongoDB user secrets.
The mongot process requires authentication credentials to
connect to your external MongoDB deployment for creating search
indexes and running search queries. This step creates the
following Kubernetes secrets:
mdb-admin-user-password- credentials for the MongoDB administrator.mdb-user-password- credentials for the user authorized to perform search queries.mdbc-rs-search-sync-source-password- credentials for a dedicated search user used internally by themongotprocess to synchronize data and manage indexes.
Kubernetes Operator mounts these secrets into the MongoDB pods.
To create the secrets, copy, paste, and run the following in the namespace where you plan to deploy MongoDB Search and Vector Search:
1 Create admin user secret 2 kubectl create secret generic mdb-admin-user-password \ 3 --from-literal=password="${MDB_ADMIN_USER_PASSWORD}" \ 4 --dry-run=client -o yaml | kubectl apply --context "${K8S_CTX}" --namespace "${MDB_NS}" -f - 5 6 Create search sync source user secret 7 kubectl create secret generic "${MDB_RESOURCE_NAME}-search-sync-source-password" \ 8 --from-literal=password="${MDB_SEARCH_SYNC_USER_PASSWORD}" \ 9 --dry-run=client -o yaml | kubectl apply --context "${K8S_CTX}" --namespace "${MDB_NS}" -f - 10 11 Create regular user secret 12 kubectl create secret generic mdb-user-password \ 13 --from-literal=password="${MDB_USER_PASSWORD}" \ 14 --dry-run=client -o yaml | kubectl apply --context "${K8S_CTX}" --namespace "${MDB_NS}" -f - 15 16 echo "User secrets created."
1 secret/mdb-admin-user-password created 2 secret/mdbc-rs-search-sync-source-password created 3 secret/mdb-user-password created
Required. Create and deploy the resource for MongoDB Search and Vector Search.
You can deploy one instance of the search node without any load balancing. To deploy, complete the following steps:
Create a MongoDBSearch custom resource named
mdbs.This resource contains the following:
spec.source.external.hostAndPortsList of external MongoDB replica set members.
spec.source.usernameSearch synchronization user username.
spec.source.passwordSecretRefSearch synchronization user password.
spec.source.external.tls.ca.nameConfigures MongoDBSearch pods to trust the external database. It points to the Kubernetes secret that contains the public CA certificate for your external MongoDB.
spec.security.tls.certificateKeySecretRef.nameSecures the MongoDBSearch service. It points to the Kubernetes secret containing the TLS server certificate and private key that the MongoDBSearch pods will present to incoming clients.
spec.resourceRequirementsCPU and memory resource requirements for the search container.
To learn more about the settings in this custom resource, see MongoDB Search and Vector Search Settings.
1 kubectl apply --context "${K8S_CTX}" -n "${MDB_NS}" -f - <<EOF 2 apiVersion: mongodb.com/v1 3 kind: MongoDBSearch 4 metadata: 5 name: ${MDB_SEARCH_RESOURCE_NAME:-mdbs} 6 spec: 7 source: 8 external: 9 hostAndPorts: 10 - ${MDB_EXTERNAL_HOST_0} 11 - ${MDB_EXTERNAL_HOST_1} 12 - ${MDB_EXTERNAL_HOST_2} 13 tls: 14 ca: 15 name: ${MDB_TLS_CA_SECRET_NAME} 16 username: search-sync-source 17 passwordSecretRef: 18 name: ${MDB_RESOURCE_NAME}-search-sync-source-password 19 key: password 20 security: 21 tls: 22 certificateKeySecretRef: 23 name: ${MDB_SEARCH_TLS_SECRET_NAME} 24 resourceRequirements: 25 limits: 26 cpu: "3" 27 memory: 5Gi 28 requests: 29 cpu: "2" 30 memory: 3Gi 31 EOF Wait for the MongoDBSearch resource deployment to complete.
When you apply the MongoDBSearch custom resource, the Kubernetes operator begins deploying the search nodes (pods). This step pauses the execution until the
mdbsresource's status phase isRunning, which indicates that the MongoDB Search StatefulSet is operational.1 echo "Waiting for MongoDBSearch resource to reach Running phase..." 2 3 kubectl --context "${K8S_CTX}" -n "${MDB_NS}" wait --for=jsonpath='{.status.phase}'=Running mdbs/"${MDB_SEARCH_RESOURCE_NAME:-mdbs}" --timeout=300s
Required. Configure external access for MongoDB Search and Vector Search.
To enable your external MongoDB instances to connect to the search service, you must configure external access for MongoDB Search and Vector Search. You can create a LoadBalancer Service that exposes the search pods outside the Kubernetes cluster.
This following service exposes the MongoDBSearch service on port 27028 with an external IP address or hostname that can be accessed from outside the Kubernetes cluster.
1 kubectl apply --context "${K8S_CTX}" -n "${MDB_NS}" -f - <<YAML 2 apiVersion: v1 3 kind: Service 4 metadata: 5 name: ${MDB_SEARCH_SERVICE_NAME} 6 spec: 7 type: LoadBalancer 8 selector: 9 app: ${MDB_SEARCH_RESOURCE_NAME:-mdbs}-search-svc 10 ports: 11 - name: mongot 12 port: 27028 13 targetPort: 27028 14 YAML 15 16 echo "Waiting for external IP to be assigned to service ${MDB_SEARCH_SERVICE_NAME}..." 17 TIMEOUT=120 # 2 minutes timeout 18 ELAPSED=0 19 while [ ${ELAPSED} -lt ${TIMEOUT} ]; do 20 EXTERNAL_IP=$(kubectl get service "${MDB_SEARCH_SERVICE_NAME}" --context "${K8S_CTX}" -n "${MDB_NS}" -o jsonpath='{.status.loadBalancer.ingress[0].ip}' 2>/dev/null) 21 if [ -n "${EXTERNAL_IP}" ] && [ "${EXTERNAL_IP}" != "null" ]; then 22 echo "External IP assigned: ${EXTERNAL_IP}" 23 break 24 fi 25 echo "Still waiting for external IP assignment... (${ELAPSED}s/${TIMEOUT}s)" 26 sleep 5 27 ELAPSED=$((ELAPSED + 5)) 28 done 29 30 if [ ${ELAPSED} -ge ${TIMEOUT} ]; then 31 echo "ERROR: Timeout reached (${TIMEOUT}s) while waiting for external IP assignment" 32 echo "LoadBalancer service may take longer to provision or there may be an issue" 33 exit 1 34 fi
Optional. View all the running pods in your namespace.
View all the running pods in your namespace pods for the MongoDB replica set members, the MongoDB Controllers for Kubernetes Operator, and the Search nodes.
1 echo; echo "MongoDBSearch resource" 2 kubectl --context "${K8S_CTX}" -n "${MDB_NS}" get mdbs/mdbs 3 echo; echo "Search pods running in cluster ${K8S_CTX}" 4 kubectl --context "${K8S_CTX}" -n "${MDB_NS}" get pods -l app=mdbs-search-svc 5 echo; echo "All pods in namespace ${MDB_NS}" 6 kubectl --context "${K8S_CTX}" -n "${MDB_NS}" get pods
1 MongoDBSearch resource 2 NAME PHASE VERSION AGE 3 mdbs Running 0.55.0 33s 4 5 Search pods running in cluster kind-kind 6 NAME READY STATUS RESTARTS AGE 7 mdbs-search-0 1/1 Running 0 33s 8 9 All pods in namespace mongodb 10 NAME READY STATUS RESTARTS AGE 11 mdbc-rs-0 2/2 Running 0 3m3s 12 mdbc-rs-1 2/2 Running 0 116s 13 mdbc-rs-2 2/2 Running 0 68s 14 mdbs-search-0 1/1 Running 0 33s 15 mongodb-kubernetes-operator-7bd6cdd889-z9w4z 1/1 Running 0 3m23s
Next Steps
Now that you've successfully deployed MongoDB Search and Vector Search to use with external MongoDB Enterprise Edition, you can add data into your MongoDB cluster, create MongoDB Search and Vector Search indexes, and run queries against your data. To learn more, see MongoDB Search and Vector Search Settings.