Kubernetes演算子 を使用して、 KubernetesクラスターにMongoDB Search とベクトル検索を配置し、外部MongoDB Enterprise Edition v8.0.10 以上のサーバーで実行できます。この手順では、 Kubernetesクラスターに mongot プロセスを配置して構成し、新規または既存の外部レプリカセット配置を使用する方法を示します。
重要
8.2 未満のMongoDBバージョンのサポートは非推奨になりました。MongoDB v8.2 以降にアップグレードします。
前提条件
MongoDB Search とベクトル検索を配置するには、次のものが必要です。
ローカルで使用可能な
kubeconfigを含む実行中のKubernetesクラスター。Kubernetesコマンドライン ツール(
kubectl)は、クラスターと通信するように構成されています。Helm、Kubernetesのパッケージマネージャーである Helm は、 Kubernetes演算子をインストールします。
このチュートリアルのコマンドを実行中には、Batch v5.1 以上が必要です。
データの保存用にバージョン 8.0.10 以降を実行中MongoDB Enterprise Editionレプリカセット。
MongoDB Enterprise の配置の詳細については、 MongoDBデータベース リソースの配置と構成 を参照してください。
MongoDBタスクを管理するための実行中のMongoDB Cloud ManagerまたはMongoDB Ops Manager 。
始める前に
Kubernetes Operator を使用してMongoDB Search とベクトル検索をインストールする前に、次の操作を行う必要があります。
MongoDB Search およびベクトル検索のCloud ManagerまたはMongoDB Ops Managerパラメーターの構成
Cloud ManagerまたはMongoDB Ops Manager UIにログインし、次の手順を実行して、 MongoDB Search およびベクトル検索用のCloud ManagerまたはMongoDB Ops Managerを構成します。
Cloud ManagerまたはMongoDB Ops Manager の配置構成を変更します。
Modify ボタンをクリックして、配置構成エディターを開きます。
[Process Configuration] セクションの下の [Advanced Configuration Options] をクリックします。
[Add Option ボタンをクリックし、ドロップダウンから [setParameter Startup Option] を選択します。
名前と値を追加した後、Add をクリックして、フィールドに次のパラメータを 1 つずつ追加します。
Parameter値mongotHost検索ホスト名とポート。例:
search-node1.example.com:27017。searchIndexManagementHostAndPort検索ホスト名とポート。例:
search-node1.example.com:27017。skipAuthenticationToSearchIndexManagementServerfalsesearchTLSMode構成された TLSモード。例、
mongotプロセスが TLS 接続を受け入れるように構成されている場合は、preferTLS。
MongoDB Search およびベクトル検索用のCloud ManagerまたはMongoDB Ops Managerユーザーの構成
searchCoordinator ロールを持つユーザーを作成する必要があります。MongoDBバージョン 8.2 以降では、searchCoordinator は組み込みロールです。ユーザーを作成し、そのユーザーにロールを割り当てる必要があります。8.2 より前のバージョンのMongoDBの場合と 8.0.10以降では、ユーザーを作成する前に、ロールを手動で作成し、権限を割り当てる必要があります。実行しているMongoDBのバージョンに対応するタブを選択して、searchCoordinator ロールを持つユーザーを作成します。
ユーザーを作成し、そのユーザーに組み込みのsearchCoordinatorロールを割り当てるには、Cloud Manager または Ops Manager UI または mongoshを使用して、次の手順を実行します。
mongosh で、次のコマンドを実行します。
ユーザーを作成し、そのユーザーに組み込み searchCoordinator ロールを割り当てるには、mongosh を使用して次の手順を実行します。
mongosh で、次のコマンドを実行します。
カスタムロールを作成します。
db.createRole({ role: "searchCoordinator", privileges: [ { resource: { db: "__mdb_internal_search", collection: "" }, actions: [ "changeStream", "collStats", "compactStructuredEncryptionData", "convertToCapped", "createCollection", "createIndex", "dbHash", "dbStats", "dropCollection", "dropIndex", "find", "insert", "killCursors", "listCollections", "listIndexes", "planCacheRead", "remove", "renameCollectionSameDB", "update" ] }, { resource: { cluster: true }, actions: [ "bypassDefaultMaxTimeMS" ] } ], roles: [ { role: "clusterMonitor", db: "admin" }, { role: "directShardOperations", db: "admin" }, { role: "readAnyDatabase", db: "admin" } ] });
環境を設定する
このチュートリアルのサンプルコードをターミナルで実行中ための環境を準備します。
必須。環境変数を設定してください。
この手順の後続のステップで使用する環境変数を設定するには、以下をコピーし、環境変数の値を設定してから、環境変数をロードします。
1 export K8S_CTX="<your kubernetes context here>" 2 3 export MDB_NS="mongodb" 4 5 export MDB_VERSION="8.0.10" 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_SEARCH_SERVICE_NAME="mdbs-search" 12 export MDB_SEARCH_HOSTNAME="mdbs-search.example.com" 13 14 # External MongoDB replica set members - REPLACE THESE VALUES with your actual external MongoDB hosts 15 # In production, replace with your actual external MongoDB replica set members 16 export MDB_EXTERNAL_HOST_0="mdbc-rs-0.mdbc-rs-svc.${MDB_NS}.svc.cluster.local:27017" 17 export MDB_EXTERNAL_HOST_1="mdbc-rs-1.mdbc-rs-svc.${MDB_NS}.svc.cluster.local:27017" 18 export MDB_EXTERNAL_HOST_2="mdbc-rs-2.mdbc-rs-svc.${MDB_NS}.svc.cluster.local:27017" 19 20 # REPLACE with your external MongoDB keyfile secret name 21 export MDB_EXTERNAL_KEYFILE_SECRET_NAME="mdbc-rs-keyfile" 22 23 # REPLACE with the actual keyfile content from your external MongoDB replica set 24 # For testing, this will be automatically generated by the MongoDB Community resource 25 export MDB_EXTERNAL_KEYFILE_CONTENT="your-mongodb-keyfile-content-CHANGE-ME" 26 27 # REPLACE with your actual external MongoDB replica set name 28 export MDB_EXTERNAL_REPLICA_SET_NAME="mdbc-rs" 29 30 export OPERATOR_HELM_CHART="mongodb/mongodb-kubernetes" 31 export OPERATOR_ADDITIONAL_HELM_VALUES="" 32 33 export MDB_CONNECTION_STRING="mongodb://mdb-user:${MDB_USER_PASSWORD}@${MDB_EXTERNAL_HOST_0}/?replicaSet=${MDB_EXTERNAL_REPLICA_SET_NAME}"
条件付き。 MongoDB Helmリポジトリを追加します。
Helm は、 Kubernetes上のMongoDBインスタンスの配置と管理を自動化します。Kubernetes Operator 演算子をインストールするための Helmチャートを含む Helmリポジトリをすでに追加している場合は、この手順をスキップします。それ以外の場合は、 Helmリポジトリを追加します。
を追加、コピー、貼り付け、実行するには、次のコマンドを実行します。
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.5.0 MongoDB Controllers for Kubernetes translate th...
条件付き。Kubernetes Operator 用のMongoDBコントロール をインストールします。
Kubernetes Operator は、MongoDB、MongoDBOpsManager、MongoDBSearch のカスタム リソースを監視し、 MongoDB配置のライフサイクルを管理します。MongoDB Controls for Kubernetes Operator をすでにインストールしている場合は、この手順をスキップします。それ以外の場合は、前の手順で追加したHelmリポジトリからMongoDB Controls for Kubernetes Operator をインストールします。
MongoDB Controls for Kubernetes Operator を mongodb名前空間にインストールするには、次のコマンドをコピー、貼り付け、実行します。
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 Oct 15 09:35:18 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.5.0 42 initAppDb: 43 name: mongodb-kubernetes-init-appdb 44 version: 1.5.0 45 initDatabase: 46 name: mongodb-kubernetes-init-database 47 version: 1.5.0 48 initOpsManager: 49 name: mongodb-kubernetes-init-ops-manager 50 version: 1.5.0 51 managedSecurityContext: false 52 mongodb: 53 appdbAssumeOldFormat: false 54 imageType: ubi8 55 name: mongodb-enterprise-server 56 repo: quay.io/mongodb 57 multiCluster: 58 clusterClientTimeout: 10 59 clusters: [] 60 kubeConfigSecretName: mongodb-enterprise-operator-multi-cluster-kubeconfig 61 performFailOver: true 62 operator: 63 additionalArguments: [] 64 affinity: {} 65 baseName: mongodb-kubernetes 66 createOperatorServiceAccount: true 67 createResourcesServiceAccountsAndRoles: true 68 deployment_name: mongodb-kubernetes-operator 69 enableClusterMongoDBRoles: true 70 enablePVCResize: true 71 env: prod 72 maxConcurrentReconciles: 1 73 mdbDefaultArchitecture: non-static 74 name: mongodb-kubernetes-operator 75 nodeSelector: {} 76 operator_image_name: mongodb-kubernetes 77 replicas: 1 78 resources: 79 limits: 80 cpu: 1100m 81 memory: 1Gi 82 requests: 83 cpu: 500m 84 memory: 200Mi 85 telemetry: 86 collection: 87 clusters: {} 88 deployments: {} 89 frequency: 1h 90 operators: {} 91 send: 92 frequency: 168h 93 tolerations: [] 94 vaultSecretBackend: 95 enabled: false 96 tlsSecretRef: "" 97 version: 1.5.0 98 watchedResources: 99 - mongodb 100 - opsmanagers 101 - mongodbusers 102 - mongodbcommunity 103 - mongodbsearch 104 webhook: 105 installClusterRole: true 106 registerConfiguration: true 107 opsManager: 108 name: mongodb-enterprise-ops-manager-ubi 109 readinessProbe: 110 name: mongodb-kubernetes-readinessprobe 111 version: 1.0.23 112 registry: 113 agent: quay.io/mongodb 114 database: quay.io/mongodb 115 imagePullSecrets: null 116 initAppDb: quay.io/mongodb 117 initDatabase: quay.io/mongodb 118 initOpsManager: quay.io/mongodb 119 operator: quay.io/mongodb 120 opsManager: quay.io/mongodb 121 pullPolicy: Always 122 readinessProbe: quay.io/mongodb 123 versionUpgradeHook: quay.io/mongodb 124 search: 125 name: mongodb-search 126 repo: quay.io/mongodb 127 version: 0.53.1 128 versionUpgradeHook: 129 name: mongodb-kubernetes-operator-version-upgrade-post-start-hook 130 version: 1.0.10 131 132 HOOKS: 133 MANIFEST: 134 --- 135 Source: mongodb-kubernetes/templates/database-roles.yaml 136 apiVersion: v1 137 kind: ServiceAccount 138 metadata: 139 name: mongodb-kubernetes-appdb 140 namespace: mongodb 141 --- 142 Source: mongodb-kubernetes/templates/database-roles.yaml 143 apiVersion: v1 144 kind: ServiceAccount 145 metadata: 146 name: mongodb-kubernetes-database-pods 147 namespace: mongodb 148 --- 149 Source: mongodb-kubernetes/templates/database-roles.yaml 150 apiVersion: v1 151 kind: ServiceAccount 152 metadata: 153 name: mongodb-kubernetes-ops-manager 154 namespace: mongodb 155 --- 156 Source: mongodb-kubernetes/templates/operator-sa.yaml 157 apiVersion: v1 158 kind: ServiceAccount 159 metadata: 160 name: mongodb-kubernetes-operator 161 namespace: mongodb 162 --- 163 Source: mongodb-kubernetes/templates/operator-roles-clustermongodbroles.yaml 164 kind: ClusterRole 165 apiVersion: rbac.authorization.k8s.io/v1 166 metadata: 167 name: mongodb-kubernetes-operator-mongodb-cluster-mongodb-role 168 rules: 169 - apiGroups: 170 - mongodb.com 171 verbs: 172 - '*' 173 resources: 174 - clustermongodbroles 175 --- 176 Source: mongodb-kubernetes/templates/operator-roles-telemetry.yaml 177 Additional ClusterRole for clusterVersionDetection 178 kind: ClusterRole 179 apiVersion: rbac.authorization.k8s.io/v1 180 metadata: 181 name: mongodb-kubernetes-operator-cluster-telemetry 182 rules: 183 Non-resource URL permissions 184 - nonResourceURLs: 185 - "/version" 186 verbs: 187 - get 188 Cluster-scoped resource permissions 189 - apiGroups: 190 - '' 191 resources: 192 - namespaces 193 resourceNames: 194 - kube-system 195 verbs: 196 - get 197 - apiGroups: 198 - '' 199 resources: 200 - nodes 201 verbs: 202 - list 203 --- 204 Source: mongodb-kubernetes/templates/operator-roles-webhook.yaml 205 kind: ClusterRole 206 apiVersion: rbac.authorization.k8s.io/v1 207 metadata: 208 name: mongodb-kubernetes-operator-mongodb-webhook-cr 209 rules: 210 - apiGroups: 211 - "admissionregistration.k8s.io" 212 resources: 213 - validatingwebhookconfigurations 214 verbs: 215 - get 216 - create 217 - update 218 - delete 219 - apiGroups: 220 - "" 221 resources: 222 - services 223 verbs: 224 - get 225 - list 226 - watch 227 - create 228 - update 229 - delete 230 --- 231 Source: mongodb-kubernetes/templates/operator-roles-clustermongodbroles.yaml 232 kind: ClusterRoleBinding 233 apiVersion: rbac.authorization.k8s.io/v1 234 metadata: 235 name: mongodb-kubernetes-operator-mongodb-cluster-mongodb-role-binding 236 roleRef: 237 apiGroup: rbac.authorization.k8s.io 238 kind: ClusterRole 239 name: mongodb-kubernetes-operator-mongodb-cluster-mongodb-role 240 subjects: 241 - kind: ServiceAccount 242 name: mongodb-kubernetes-operator 243 namespace: mongodb 244 --- 245 Source: mongodb-kubernetes/templates/operator-roles-telemetry.yaml 246 ClusterRoleBinding for clusterVersionDetection 247 kind: ClusterRoleBinding 248 apiVersion: rbac.authorization.k8s.io/v1 249 metadata: 250 name: mongodb-kubernetes-operator-mongodb-cluster-telemetry-binding 251 roleRef: 252 apiGroup: rbac.authorization.k8s.io 253 kind: ClusterRole 254 name: mongodb-kubernetes-operator-cluster-telemetry 255 subjects: 256 - kind: ServiceAccount 257 name: mongodb-kubernetes-operator 258 namespace: mongodb 259 --- 260 Source: mongodb-kubernetes/templates/operator-roles-webhook.yaml 261 kind: ClusterRoleBinding 262 apiVersion: rbac.authorization.k8s.io/v1 263 metadata: 264 name: mongodb-kubernetes-operator-mongodb-webhook-crb 265 roleRef: 266 apiGroup: rbac.authorization.k8s.io 267 kind: ClusterRole 268 name: mongodb-kubernetes-operator-mongodb-webhook-cr 269 subjects: 270 - kind: ServiceAccount 271 name: mongodb-kubernetes-operator 272 namespace: mongodb 273 --- 274 Source: mongodb-kubernetes/templates/database-roles.yaml 275 kind: Role 276 apiVersion: rbac.authorization.k8s.io/v1 277 metadata: 278 name: mongodb-kubernetes-appdb 279 namespace: mongodb 280 rules: 281 - apiGroups: 282 - '' 283 resources: 284 - secrets 285 verbs: 286 - get 287 - apiGroups: 288 - '' 289 resources: 290 - pods 291 verbs: 292 - patch 293 - delete 294 - get 295 --- 296 Source: mongodb-kubernetes/templates/operator-roles-base.yaml 297 kind: Role 298 apiVersion: rbac.authorization.k8s.io/v1 299 metadata: 300 name: mongodb-kubernetes-operator 301 namespace: mongodb 302 rules: 303 - apiGroups: 304 - '' 305 resources: 306 - services 307 verbs: 308 - get 309 - list 310 - watch 311 - create 312 - update 313 - delete 314 - apiGroups: 315 - '' 316 resources: 317 - secrets 318 - configmaps 319 verbs: 320 - get 321 - list 322 - create 323 - update 324 - delete 325 - watch 326 - apiGroups: 327 - apps 328 resources: 329 - statefulsets 330 verbs: 331 - create 332 - get 333 - list 334 - watch 335 - delete 336 - update 337 - apiGroups: 338 - '' 339 resources: 340 - pods 341 verbs: 342 - get 343 - list 344 - watch 345 - delete 346 - deletecollection 347 - apiGroups: 348 - mongodbcommunity.mongodb.com 349 resources: 350 - mongodbcommunity 351 - mongodbcommunity/status 352 - mongodbcommunity/spec 353 - mongodbcommunity/finalizers 354 verbs: 355 - '*' 356 - apiGroups: 357 - mongodb.com 358 verbs: 359 - '*' 360 resources: 361 - mongodb 362 - mongodb/finalizers 363 - mongodbusers 364 - mongodbusers/finalizers 365 - opsmanagers 366 - opsmanagers/finalizers 367 - mongodbmulticluster 368 - mongodbmulticluster/finalizers 369 - mongodbsearch 370 - mongodbsearch/finalizers 371 - mongodb/status 372 - mongodbusers/status 373 - opsmanagers/status 374 - mongodbmulticluster/status 375 - mongodbsearch/status 376 --- 377 Source: mongodb-kubernetes/templates/operator-roles-pvc-resize.yaml 378 kind: Role 379 apiVersion: rbac.authorization.k8s.io/v1 380 metadata: 381 name: mongodb-kubernetes-operator-pvc-resize 382 namespace: mongodb 383 rules: 384 - apiGroups: 385 - '' 386 resources: 387 - persistentvolumeclaims 388 verbs: 389 - get 390 - delete 391 - list 392 - watch 393 - patch 394 - update 395 --- 396 Source: mongodb-kubernetes/templates/database-roles.yaml 397 kind: RoleBinding 398 apiVersion: rbac.authorization.k8s.io/v1 399 metadata: 400 name: mongodb-kubernetes-appdb 401 namespace: mongodb 402 roleRef: 403 apiGroup: rbac.authorization.k8s.io 404 kind: Role 405 name: mongodb-kubernetes-appdb 406 subjects: 407 - kind: ServiceAccount 408 name: mongodb-kubernetes-appdb 409 namespace: mongodb 410 --- 411 Source: mongodb-kubernetes/templates/operator-roles-base.yaml 412 kind: RoleBinding 413 apiVersion: rbac.authorization.k8s.io/v1 414 metadata: 415 name: mongodb-kubernetes-operator 416 namespace: mongodb 417 roleRef: 418 apiGroup: rbac.authorization.k8s.io 419 kind: Role 420 name: mongodb-kubernetes-operator 421 subjects: 422 - kind: ServiceAccount 423 name: mongodb-kubernetes-operator 424 namespace: mongodb 425 --- 426 Source: mongodb-kubernetes/templates/operator-roles-pvc-resize.yaml 427 kind: RoleBinding 428 apiVersion: rbac.authorization.k8s.io/v1 429 metadata: 430 name: mongodb-kubernetes-operator-pvc-resize-binding 431 namespace: mongodb 432 roleRef: 433 apiGroup: rbac.authorization.k8s.io 434 kind: Role 435 name: mongodb-kubernetes-operator-pvc-resize 436 subjects: 437 - kind: ServiceAccount 438 name: mongodb-kubernetes-operator 439 namespace: mongodb 440 --- 441 Source: mongodb-kubernetes/templates/operator.yaml 442 apiVersion: apps/v1 443 kind: Deployment 444 metadata: 445 name: mongodb-kubernetes-operator 446 namespace: mongodb 447 spec: 448 replicas: 1 449 selector: 450 matchLabels: 451 app.kubernetes.io/component: controller 452 app.kubernetes.io/name: mongodb-kubernetes-operator 453 app.kubernetes.io/instance: mongodb-kubernetes-operator 454 template: 455 metadata: 456 labels: 457 app.kubernetes.io/component: controller 458 app.kubernetes.io/name: mongodb-kubernetes-operator 459 app.kubernetes.io/instance: mongodb-kubernetes-operator 460 spec: 461 serviceAccountName: mongodb-kubernetes-operator 462 securityContext: 463 runAsNonRoot: true 464 runAsUser: 2000 465 containers: 466 - name: mongodb-kubernetes-operator 467 image: "quay.io/mongodb/mongodb-kubernetes:1.5.0" 468 imagePullPolicy: Always 469 args: 470 - -watch-resource=mongodb 471 - -watch-resource=opsmanagers 472 - -watch-resource=mongodbusers 473 - -watch-resource=mongodbcommunity 474 - -watch-resource=mongodbsearch 475 - -watch-resource=clustermongodbroles 476 command: 477 - /usr/local/bin/mongodb-kubernetes-operator 478 resources: 479 limits: 480 cpu: 1100m 481 memory: 1Gi 482 requests: 483 cpu: 500m 484 memory: 200Mi 485 env: 486 - name: OPERATOR_ENV 487 value: prod 488 - name: MDB_DEFAULT_ARCHITECTURE 489 value: non-static 490 - name: NAMESPACE 491 valueFrom: 492 fieldRef: 493 fieldPath: metadata.namespace 494 - name: WATCH_NAMESPACE 495 valueFrom: 496 fieldRef: 497 fieldPath: metadata.namespace 498 - name: MDB_OPERATOR_TELEMETRY_COLLECTION_FREQUENCY 499 value: "1h" 500 - name: MDB_OPERATOR_TELEMETRY_SEND_FREQUENCY 501 value: "168h" 502 - name: CLUSTER_CLIENT_TIMEOUT 503 value: "10" 504 - name: IMAGE_PULL_POLICY 505 value: Always 506 # Database 507 - name: MONGODB_ENTERPRISE_DATABASE_IMAGE 508 value: quay.io/mongodb/mongodb-kubernetes-database 509 - name: INIT_DATABASE_IMAGE_REPOSITORY 510 value: quay.io/mongodb/mongodb-kubernetes-init-database 511 - name: INIT_DATABASE_VERSION 512 value: 1.5.0 513 - name: DATABASE_VERSION 514 value: 1.5.0 515 # Ops Manager 516 - name: OPS_MANAGER_IMAGE_REPOSITORY 517 value: quay.io/mongodb/mongodb-enterprise-ops-manager-ubi 518 - name: INIT_OPS_MANAGER_IMAGE_REPOSITORY 519 value: quay.io/mongodb/mongodb-kubernetes-init-ops-manager 520 - name: INIT_OPS_MANAGER_VERSION 521 value: 1.5.0 522 # AppDB 523 - name: INIT_APPDB_IMAGE_REPOSITORY 524 value: quay.io/mongodb/mongodb-kubernetes-init-appdb 525 - name: INIT_APPDB_VERSION 526 value: 1.5.0 527 - name: OPS_MANAGER_IMAGE_PULL_POLICY 528 value: Always 529 - name: AGENT_IMAGE 530 value: "quay.io/mongodb/mongodb-agent:108.0.12.8846-1" 531 - name: MDB_AGENT_IMAGE_REPOSITORY 532 value: "quay.io/mongodb/mongodb-agent" 533 - name: MONGODB_IMAGE 534 value: mongodb-enterprise-server 535 - name: MONGODB_REPO_URL 536 value: quay.io/mongodb 537 - name: MDB_IMAGE_TYPE 538 value: ubi8 539 - name: PERFORM_FAILOVER 540 value: 'true' 541 - name: MDB_MAX_CONCURRENT_RECONCILES 542 value: "1" 543 - name: POD_NAME 544 valueFrom: 545 fieldRef: 546 fieldPath: metadata.name 547 - name: OPERATOR_NAME 548 value: mongodb-kubernetes-operator 549 # Community Env Vars Start 550 - name: MDB_COMMUNITY_AGENT_IMAGE 551 value: "quay.io/mongodb/mongodb-agent:108.0.2.8729-1" 552 - name: VERSION_UPGRADE_HOOK_IMAGE 553 value: "quay.io/mongodb/mongodb-kubernetes-operator-version-upgrade-post-start-hook:1.0.10" 554 - name: READINESS_PROBE_IMAGE 555 value: "quay.io/mongodb/mongodb-kubernetes-readinessprobe:1.0.23" 556 - name: MDB_COMMUNITY_IMAGE 557 value: "mongodb-community-server" 558 - name: MDB_COMMUNITY_REPO_URL 559 value: "quay.io/mongodb" 560 - name: MDB_COMMUNITY_IMAGE_TYPE 561 value: "ubi8" 562 # Community Env Vars End 563 - name: MDB_SEARCH_REPO_URL 564 value: "quay.io/mongodb" 565 - name: MDB_SEARCH_NAME 566 value: "mongodb-search" 567 - name: MDB_SEARCH_VERSION 568 value: "0.53.1"
上記のコマンドは、 Kubernetes Operator を mongodb名前空間にインストールします。このコマンドは、まだ存在しない場合は作成します。インストール後、 Kubernetes Operator は MongoDBSearch カスタム リソースを監視し、 MongoDB Search とベクトル検索配置のライフサイクルを管理します。
MongoDB Search とベクトル検索をインストールする
必須。MongoDBユーザーシークレットを作成してロードします。
mongot プロセスでは、検索インデックスを作成し、検索クエリを実行中ために外部MongoDBデプロイに接続するための認証情報が必要です。この手順では、次のKubernetesシークレットが作成されます。
mdb-admin-user-password- MongoDB管理者の認証情報。mdb-user-password- 検索クエリを実行する権限を持つユーザーの認証情報。mdbc-rs-search-sync-source-password- データを同期し、インデックスを管理するためにmongotプロセスによって内部的に使用される専用検索ユーザーの認証情報。
Kubernetes Operator はこれらのシークレットをMongoDBポッドにマウントします。
シークレットを作成するには、 MongoDB Search とベクトル検索を配置する予定の名前空間で、以下をコピーして貼り付け、実行します。
1 kubectl --context "${K8S_CTX}" --namespace "${MDB_NS}" \ 2 create secret generic mdb-admin-user-password \ 3 --from-literal=password="${MDB_ADMIN_USER_PASSWORD}" 4 5 kubectl --context "${K8S_CTX}" --namespace "${MDB_NS}" \ 6 create secret generic mdbc-rs-search-sync-source-password \ 7 --from-literal=password="${MDB_SEARCH_SYNC_USER_PASSWORD}" 8 9 kubectl --context "${K8S_CTX}" --namespace "${MDB_NS}" \ 10 create secret generic mdb-user-password \ 11 --from-literal=password="${MDB_USER_PASSWORD}"
1 secret/mdb-admin-user-password created 2 secret/mdbc-rs-search-sync-source-password created 3 secret/mdb-user-password created
必須。 への接続に使用するキーファイルmongod シークレットを配置します。
外部MongoDBからの接続を認証するために、mongot プロセスは外部MongoDBレプリカセットノードがレプリカセットノード間の内部認証に使用するのと同じキーファイルを使用します。
外部MongoDBから キーファイル コンテンツを含むKubernetesシークレットを作成するには、次のコマンドをコピーして貼り付け、実行します。
1 kubectl --context "${K8S_CTX}" --namespace "${MDB_NS}" \ 2 create secret generic "${MDB_EXTERNAL_KEYFILE_SECRET_NAME}" \ 3 --from-literal=keyfile="${MDB_EXTERNAL_KEYFILE_CONTENT}"
必須。MongoDB Search とベクトル検索のリソースを作成して配置します 。
負荷分散なしで、検索ノードの 1 つのインスタンスを配置できます。配置するには、次の手順を実行します。
mdbsという名前のMongoDBSearchカスタムリソースを作成します。このリソースには、次のものが含まれています。
spec.source.external.hostAndPorts外部MongoDBレプリカセットノードのリスト。
spec.source.external.keyfileSecretRef外部レプリカセットノードによって使用されるキーファイル シークレット。
spec.source.username同期ユーザーユーザー名 を検索します。
spec.source.passwordSecretRef同期ユーザーのパスワードを検索します。
spec.resourceRequirements検索コンテナの CPU とメモリリソースの要件。
このカスタムリソースの設定の詳細については、MongoDB Search とベクトル検索の設定を参照してください。
1 kubectl apply --context "${K8S_CTX}" -n "${MDB_NS}" -f - <<EOF 2 apiVersion: mongodb.com/v1 3 kind: MongoDBSearch 4 metadata: 5 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 keyfileSecretRef: 14 name: ${MDB_EXTERNAL_KEYFILE_SECRET_NAME} 15 key: keyfile 16 username: search-sync-source 17 passwordSecretRef: 18 name: ${MDB_RESOURCE_NAME}-search-sync-source-password 19 key: password 20 resourceRequirements: 21 limits: 22 cpu: "3" 23 memory: 5Gi 24 requests: 25 cpu: "2" 26 memory: 3Gi 27 EOF MongoDBSearchリソースの配置が完了するまで待ちます。MongoDBSearchカスタムリソースを適用すると、 Kubernetes演算子による検索ノード(ポッド)の配置が開始されます。このステップでは、mdbsリソースのステータス フェーズがRunningになるまで実行を一時停止します。これはMongoDB Search ステートメントが操作可能であることを示します。1 echo "Waiting for MongoDBSearch resource to reach Running phase..." 2 kubectl --context "${K8S_CTX}" -n "${MDB_NS}" wait \ 3 --for=jsonpath='{.status.phase}'=Running mdbs/mdbs --timeout=300s
必須。MongoDB Search とベクトル検索の外部アクセスを構成します。
外部MongoDBインスタンスが検索サービスに接続できるようにするには、 MongoDB Search とベクトル検索の外部アクセスを構成する必要があります。検索ポッドをKubernetesクラスターの外部に公開する LoadBalancer サービスを作成できます。
このサービスは、 Kubernetesクラスターの外部からアクセスできる外部IPアドレスまたはホスト名を使用して、ポート 27027 の MongoDBSearch サービスを公開します。
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: mdbs-search-svc 10 ports: 11 - name: mongot 12 port: 27027 13 targetPort: 27027 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
任意。名前空間で実行中のすべてのポッドを表示します。
MongoDBレプリカセットノード、 Kubernetes演算子用のMongoDBコントロール、および検索ノードの名前空間ポッド内のすべての実行中中のポッドを表示します。
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 AGE 3 mdbs Running 31s 4 5 Search pods running in cluster kind-kind 6 NAME READY STATUS RESTARTS AGE 7 mdbs-search-0 1/1 Running 0 31s 8 9 All pods in namespace mongodb 10 NAME READY STATUS RESTARTS AGE 11 mdbc-rs-0 2/2 Running 0 3m11s 12 mdbc-rs-1 2/2 Running 0 2m 13 mdbc-rs-2 2/2 Running 0 73s 14 mdbs-search-0 1/1 Running 0 31s 15 mongodb-kubernetes-operator-57c6f46b47-8nwp6 1/1 Running 0 3m14s
次のステップ
MongoDB Search とベクトル検索を正常に配置して外部のMongoDB Enterprise Edition で使用することができたら、 MongoDBクラスターにデータを追加し、 MongoDB Search とベクトル検索インデックスを作成し、データに対してクエリを実行できます。詳細については、 MongoDB Search とベクトル検索 の設定 を参照してください。