Você pode usar o Kubernetes Operator para implantar recursos do MongoDB Search e Vector Search para serem executados com o MongoDB Enterprise v8.2.0 ou superior em um cluster do Kubernetes. Este procedimento demonstra como implantar e configurar o mongot processo para ser executado com um conjunto de réplicas novo ou existente em seu cluster Kubernetes. A implantação usa certificadosTLS para garantir uma comunicação segura entre os nós do MongoDB e o mongot processo de pesquisa.
Pré-requisitos
Para implantar o MongoDB Search e o Vector Search, você deve ter o seguinte:
Um cluster Kubernetes em execução com
kubeconfigdisponível localmente.A ferramenta de linha de comando do Kubernetes,
kubectl, configurada para se comunicar com seu cluster.Helm, o gerenciador de pacote do Kubernetes, para instalar o Operador Kubernetes.
Bash v5.1 ou superior para executar os comandos neste tutorial.
projeto MongoDB Ops Manager ou MongoDB Cloud Manager e credenciais de API.
Procedimento
Obrigatório. Defina as variáveis de ambiente.
Defina as variáveis de ambiente para uso nas etapas subsequentes deste procedimento. Copie os seguintes comandos, atualize os valores do seu ambiente e execute-os para carregar as variáveis:
1 # set it to the context name of the k8s cluster 2 export K8S_CTX="<local cluster context>" 3 4 # the following namespace will be created if not exists 5 export MDB_NS="mongodb" 6 7 # name of the MongoDB Custom Resource. 8 export MDB_RESOURCE_NAME="mdb-rs" 9 10 export MDB_MEMBERS=3 11 # OM/CM's project name to be used to manage mongodb replica set 12 export OPS_MANAGER_PROJECT_NAME="<arbitrary project name>" 13 14 # URL to Cloud Manager or Ops Manager instance 15 export OPS_MANAGER_API_URL="https://cloud-qa.mongodb.com" 16 17 # The API key can be an Org Owner - the operator can create the project automatically then. 18 # The API key can also be created in a particular project that was created manually with the Project Owner scope. 19 export OPS_MANAGER_API_USER="<SET API USER>" 20 export OPS_MANAGER_API_KEY="<SET API KEY>" 21 export OPS_MANAGER_ORG_ID="<SET ORG ID>" 22 23 # minimum required MongoDB version for running MongoDB Search is 8.2.0 24 export MDB_VERSION="8.2.0-ent" 25 26 # root admin user for convenience, not used here at all in this guide 27 export MDB_ADMIN_USER_PASSWORD="admin-user-password-CHANGE-ME" 28 # regular user performing restore and search queries on sample mflix database 29 export MDB_USER_PASSWORD="mdb-user-password-CHANGE-ME" 30 # user for MongoDB Search to connect to the replica set to synchronise data from 31 export MDB_SEARCH_SYNC_USER_PASSWORD="search-sync-user-password-CHANGE-ME" 32 33 export OPERATOR_HELM_CHART="mongodb/mongodb-kubernetes" 34 # comma-separated key=value pairs for additional parameters passed to the helm-chart installing the operator 35 export OPERATOR_ADDITIONAL_HELM_VALUES="" 36 37 export MDB_TLS_CERT_SECRET_PREFIX="certs" 38 export MDB_TLS_CA_CONFIGMAP="${MDB_RESOURCE_NAME}-ca-configmap" 39 40 export CERT_MANAGER_NAMESPACE="cert-manager" 41 export MDB_TLS_SELF_SIGNED_ISSUER="selfsigned-bootstrap-issuer" 42 export MDB_TLS_CA_CERT_NAME="my-selfsigned-ca" 43 export MDB_TLS_CA_SECRET_NAME="root-secret" 44 export MDB_TLS_CA_ISSUER="my-ca-issuer" 45 export MDB_TLS_SERVER_CERT_SECRET_NAME="${MDB_TLS_CERT_SECRET_PREFIX}-${MDB_RESOURCE_NAME}-cert" 46 export MDB_SEARCH_TLS_SECRET_NAME="${MDB_RESOURCE_NAME}-search-tls" 47 48 export MDB_CONNECTION_STRING="mongodb://mdb-user:${MDB_USER_PASSWORD}@${MDB_RESOURCE_NAME}-svc.${MDB_NS}.svc.cluster.local:27017/?replicaSet=${MDB_RESOURCE_NAME}&tls=true&tlsCAFile=/tls/ca.crt"
Para verificar se todas as variáveis de ambiente necessárias estão definidas, execute o seguinte código em seu terminal:
1 required=( 2 K8S_CTX 3 MDB_NS 4 MDB_RESOURCE_NAME 5 MDB_VERSION 6 MDB_MEMBERS 7 CERT_MANAGER_NAMESPACE 8 MDB_TLS_CA_SECRET_NAME 9 MDB_TLS_SERVER_CERT_SECRET_NAME 10 MDB_SEARCH_TLS_SECRET_NAME 11 MDB_ADMIN_USER_PASSWORD 12 MDB_SEARCH_SYNC_USER_PASSWORD 13 MDB_USER_PASSWORD 14 OPERATOR_HELM_CHART 15 OPS_MANAGER_PROJECT_NAME 16 OPS_MANAGER_API_URL 17 OPS_MANAGER_API_USER 18 OPS_MANAGER_API_KEY 19 ) 20 21 missing_req=() 22 for v in "${required[@]}"; do [[ -n "${!v:-}" ]] || missing_req+=("${v}"); done 23 if (( ${#missing_req[@]} )); then 24 echo "ERROR: Missing required environment variables:" >&2 25 for m in "${missing_req[@]}"; do echo " - ${m}" >&2; done 26 else 27 echo "All required environment variables present." 28 fi
Condicional. Adicione o repositório do MongoDB Helm.
O Helm automatiza a implantação e o gerenciamento de instâncias do MongoDB no Kubernetes. Se você já adicionou o repositório Helm que contém o gráfico Helm para instalar o operador Kubernetes Operator, pule esta etapa. Caso contrário, adicione o repositório Helm.
Para adicionar, copie, cole e execute o seguinte comando:
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...
Condicional. Instale os drivers do MongoDB para o Kubernetes Operator.
O Operador Kubernetes observa MongoDB, MongoDBOpsManager e MongoDBSearch recursos personalizados e gerencia o ciclo de vida de suas implantações do MongoDB . Se você já instalou os Controladores MongoDB para Kubernetes Operator, pule esta etapa. Caso contrário, instale os Controladores MongoDB para Kubernetes Operator a partir do repositório Helm que você adicionou na etapa anterior.
Para instalar os Controladores MongoDB para o Operador Kubernetes no namespace do mongodb, copie, cole e execute o seguinte:
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"
Condicional. Instale cert-manager o.
O cert-manager é necessário para gerenciar certificados TLS. Se você já tiver cert-manager o instalado em seu cluster, pule esta etapa. Caso contrário, instale cert-manager usando o Helm.
Para instalar o cert-manager no namespace cert-manager, execute o seguinte comando em seu terminal:
1 helm upgrade --install \ 2 cert-manager \ 3 oci://quay.io/jetstack/charts/cert-manager \ 4 --kube-context "${K8S_CTX}" \ 5 --namespace "${CERT_MANAGER_NAMESPACE}" \ 6 --create-namespace \ 7 --set crds.enabled=true 8 9 for deployment in cert-manager cert-manager-cainjector cert-manager-webhook; do 10 kubectl --context "${K8S_CTX}" \ 11 -n "${CERT_MANAGER_NAMESPACE}" \ 12 wait --for=condition=Available "deployment/${deployment}" --timeout=300s 13 done 14 15 echo "cert-manager is ready in namespace ${CERT_MANAGER_NAMESPACE}."
Obrigatório. Prepare o emissor do certificado e a infraestrutura da CA.
Crie a infraestrutura da autoridade de certificação que emitirá certificados TLS MongoDB para MongoDBSearch recursos e. Os comandos executam as seguintes ações:
Crie um
ClusterIssuerautoassinado.Gere um certificado CA.
Publique um emissor de CA em todo o cluster que todos os namespaces possam usar.
Exponha o pacote CA por meio de um
ConfigMappara que os recursos do MongoDB possam usá-lo.
1 Bootstrap a self-signed ClusterIssuer to mint the CA secret consumed by application workloads. 2 kubectl apply --context "${K8S_CTX}" -f - <<EOF_MANIFEST 3 apiVersion: cert-manager.io/v1 4 kind: ClusterIssuer 5 metadata: 6 name: ${MDB_TLS_SELF_SIGNED_ISSUER} 7 spec: 8 selfSigned: {} 9 EOF_MANIFEST 10 11 kubectl --context "${K8S_CTX}" wait --for=condition=Ready clusterissuer "${MDB_TLS_SELF_SIGNED_ISSUER}" 12 13 kubectl apply --context "${K8S_CTX}" -f - <<EOF_MANIFEST 14 apiVersion: cert-manager.io/v1 15 kind: Certificate 16 metadata: 17 name: ${MDB_TLS_CA_CERT_NAME} 18 namespace: ${CERT_MANAGER_NAMESPACE} 19 spec: 20 isCA: true 21 commonName: ${MDB_TLS_CA_CERT_NAME} 22 secretName: ${MDB_TLS_CA_SECRET_NAME} 23 privateKey: 24 algorithm: ECDSA 25 size: 256 26 issuerRef: 27 name: ${MDB_TLS_SELF_SIGNED_ISSUER} 28 kind: ClusterIssuer 29 EOF_MANIFEST 30 31 kubectl --context "${K8S_CTX}" wait --for=condition=Ready -n "${CERT_MANAGER_NAMESPACE}" certificate "${MDB_TLS_CA_CERT_NAME}" 32 33 kubectl apply --context "${K8S_CTX}" -f - <<EOF_MANIFEST 34 apiVersion: cert-manager.io/v1 35 kind: ClusterIssuer 36 metadata: 37 name: ${MDB_TLS_CA_ISSUER} 38 spec: 39 ca: 40 secretName: ${MDB_TLS_CA_SECRET_NAME} 41 EOF_MANIFEST 42 43 kubectl --context "${K8S_CTX}" wait --for=condition=Ready clusterissuer "${MDB_TLS_CA_ISSUER}" 44 45 TMP_CA_CERT="$(mktemp)" 46 trap 'rm -f "${TMP_CA_CERT}"' EXIT 47 48 kubectl --context "${K8S_CTX}" get secret "${MDB_TLS_CA_SECRET_NAME}" -n "${CERT_MANAGER_NAMESPACE}" -o jsonpath="{.data['ca\\.crt']}" | base64 --decode > "${TMP_CA_CERT}" 49 50 kubectl --context "${K8S_CTX}" create configmap "${MDB_TLS_CA_CONFIGMAP}" -n "${MDB_NS}" \ 51 --from-file=ca-pem="${TMP_CA_CERT}" --from-file=mms-ca.crt="${TMP_CA_CERT}" \ 52 --from-file=ca.crt="${TMP_CA_CERT}" \ 53 --dry-run=client -o yaml | kubectl --context "${K8S_CTX}" apply -f -
Obrigatório. Emita certificados TLS.
Emita certificados TLS para o servidor MongoDB (${MDB_RESOURCE_NAME}-server-tls) e o serviço MongoDBSearch (${MDB_RESOURCE_NAME}-search-tls). O certificado de servidor MongoDB inclui todos os nomes de DNS necessários para o pod e a comunicação de serviço. Ambos os certificados dão suporte à autenticação de servidor e cliente.
1 server_certificate="${MDB_RESOURCE_NAME}-server-tls" 2 search_certificate="${MDB_RESOURCE_NAME}-search-tls" 3 4 mongo_dns_names=() 5 for ((member = 0; member < MDB_MEMBERS; member++)); do 6 mongo_dns_names+=("${MDB_RESOURCE_NAME}-${member}") 7 mongo_dns_names+=("${MDB_RESOURCE_NAME}-${member}.${MDB_RESOURCE_NAME}-svc.${MDB_NS}.svc.cluster.local") 8 done 9 mongo_dns_names+=( 10 "${MDB_RESOURCE_NAME}-svc.${MDB_NS}.svc.cluster.local" 11 "*.${MDB_RESOURCE_NAME}-svc.${MDB_NS}.svc.cluster.local" 12 ) 13 14 search_dns_names=( 15 "${MDB_RESOURCE_NAME}-search-svc.${MDB_NS}.svc.cluster.local" 16 ) 17 18 render_dns_list() { 19 local dns_list=("$@") 20 for dns in "${dns_list[@]}"; do 21 printf " - \"%s\"\n" "${dns}" 22 done 23 } 24 25 kubectl apply --context "${K8S_CTX}" -n "${MDB_NS}" -f - <<EOF_MANIFEST 26 apiVersion: cert-manager.io/v1 27 kind: Certificate 28 metadata: 29 name: ${server_certificate} 30 namespace: ${MDB_NS} 31 spec: 32 secretName: ${MDB_TLS_SERVER_CERT_SECRET_NAME} 33 issuerRef: 34 name: ${MDB_TLS_CA_ISSUER} 35 kind: ClusterIssuer 36 duration: 240h0m0s 37 renewBefore: 120h0m0s 38 usages: 39 - digital signature 40 - key encipherment 41 - server auth 42 - client auth 43 dnsNames: 44 (render_dns_list "${mongo_dns_names[@]}") 45 --- 46 apiVersion: cert-manager.io/v1 47 kind: Certificate 48 metadata: 49 name: ${search_certificate} 50 namespace: ${MDB_NS} 51 spec: 52 secretName: ${MDB_SEARCH_TLS_SECRET_NAME} 53 issuerRef: 54 name: ${MDB_TLS_CA_ISSUER} 55 kind: ClusterIssuer 56 duration: 240h0m0s 57 renewBefore: 120h0m0s 58 usages: 59 - digital signature 60 - key encipherment 61 - server auth 62 - client auth 63 dnsNames: 64 (render_dns_list "${search_dns_names[@]}") 65 EOF_MANIFEST 66 67 kubectl --context "${K8S_CTX}" -n "${MDB_NS}" wait --for=condition=Ready certificate "${server_certificate}" --timeout=300s 68 kubectl --context "${K8S_CTX}" -n "${MDB_NS}" wait --for=condition=Ready certificate "${search_certificate}" --timeout=300s
Condicional. Crie e implemente o recurso MongoDB Enterprise .
Se você já implementou o MongoDB Enterprise, pule para a próxima etapa. Caso contrário, implemente o recurso MongoDB Enterprise .
Para implementar o MongoDB Enterprise, complete as seguintes etapas:
Crie o ConfigMap e o segredo para o projeto MongoDB Ops Manager se estiver usando o MongoDB Ops Manager.
Para armazenar a configuração e as credenciais para integração com o MongoDB Ops Manager, copie, cole e execute os seguintes comandos:
1 kubectl --context "${K8S_CTX}" -n "${MDB_NS}" create configmap om-project \ 2 --from-literal=projectName="${OPS_MANAGER_PROJECT_NAME}" --from-literal=baseUrl="${OPS_MANAGER_API_URL}" \ 3 --from-literal=orgId="${OPS_MANAGER_ORG_ID:-}" 4 5 kubectl --context "${K8S_CTX}" -n "${MDB_NS}" create secret generic om-credentials \ 6 --from-literal=publicKey="${OPS_MANAGER_API_USER}" \ 7 --from-literal=privateKey="${OPS_MANAGER_API_KEY}" Crie um recurso personalizado do
MongoDBdenominadomdb-rs.O recurso define os recursos de memória e CPU para os containers
mongodemongodb-agente instrui o Operador Kubernetes a configurar um conjunto de réplicas do MongoDB com membros 3:Para implantar o MongoDB Enterprise, copie, cole e execute o seguinte no namespace:
1 kubectl apply --context "${K8S_CTX}" -n "${MDB_NS}" -f - <<EOF 2 apiVersion: mongodb.com/v1 3 kind: MongoDB 4 metadata: 5 name: ${MDB_RESOURCE_NAME} 6 spec: 7 members: ${MDB_MEMBERS} 8 version: ${MDB_VERSION} 9 type: ReplicaSet 10 opsManager: 11 configMapRef: 12 name: om-project 13 credentials: om-credentials 14 security: 15 authentication: 16 enabled: true 17 ignoreUnknownUsers: true 18 modes: 19 - SCRAM 20 certsSecretPrefix: ${MDB_TLS_CERT_SECRET_PREFIX} 21 tls: 22 enabled: true 23 ca: ${MDB_TLS_CA_CONFIGMAP} 24 agent: 25 logLevel: INFO 26 podSpec: 27 podTemplate: 28 spec: 29 containers: 30 - name: mongodb-enterprise-database 31 resources: 32 limits: 33 cpu: "2" 34 memory: 2Gi 35 requests: 36 cpu: "1" 37 memory: 1Gi 38 EOF Aguarde a conclusão do sistema de recursos
MongoDB.Quando você aplica o recurso personalizado do
MongoDB, o operador Kubernetes começa a distribuir os nós MongoDB (Pods). Essa etapa pausa a execução até que a fase de status do recursomdbc-rssejaRunning, o que indica que o conjunto de réplicas da MongoDB Community está operacional.1 echo "Waiting for MongoDB resource to reach Running phase..." 2 kubectl --context "${K8S_CTX}" -n "${MDB_NS}" wait --for=jsonpath='{.status.phase}'=Running "mdb/${MDB_RESOURCE_NAME}" --timeout=400s 3 echo; echo "MongoDB resource" 4 kubectl --context "${K8S_CTX}" -n "${MDB_NS}" get "mdb/${MDB_RESOURCE_NAME}" 5 echo; echo "Pods running in cluster ${K8S_CTX}" 6 kubectl --context "${K8S_CTX}" -n "${MDB_NS}" get pods 1 Waiting for MongoDB resource to reach Running phase... 2 mongodb.mongodb.mongodb.com/mdbc-rs condition met 3 4 MongoDB resource 5 NAME PHASE VERSION 6 mdbc-rs Running 8.2 7 8 Pods running in cluster minikube 9 NAME READY STATUS RESTARTS AGE 10 mdbc-rs-0 2/2 Running 0 2m30s 11 mdbc-rs-1 2/2 Running 0 82s 12 mdbc-rs-2 2/2 Running 0 38s 13 mongodb-kubernetes-operator-5776c8b4df-cppnf 1/1 Running 0 7m37s
Obrigatório. Crie e carregue os segredos de usuário MongoDB .
O MongoDB requer autenticação para acesso seguro. Nesta etapa, você cria três segredos do Kubernetes:
mdb-admin-user-password: Credenciais do administrador do MongoDB .mdb-user-password: Credenciais do usuário autorizado a realizar queries de pesquisa.mdbc-rs-search-sync-source-password: Credenciais para um usuário de pesquisa dedicado utilizado internamente pelo processo domongotpara sincronizar dados e gerenciar índices.
O Kubernetes Operator monta esses segredos nos pods do MongoDB .
Para criar os segredos, copie, cole e execute o seguinte no namespace onde você distribuiu o MongoDB Server e planeja implantar a Pesquisa MongoDB e a Vector Search:
1 admin user with root role 2 kubectl --context "${K8S_CTX}" --namespace "${MDB_NS}" \ 3 create secret generic mdb-admin-user-password \ 4 --from-literal=password="${MDB_ADMIN_USER_PASSWORD}" 5 6 kubectl apply --context "${K8S_CTX}" -n "${MDB_NS}" -f - <<EOF 7 apiVersion: mongodb.com/v1 8 kind: MongoDBUser 9 metadata: 10 name: mdb-admin 11 spec: 12 username: mdb-admin 13 db: admin 14 mongodbResourceRef: 15 name: ${MDB_RESOURCE_NAME} 16 passwordSecretKeyRef: 17 name: mdb-admin-user-password 18 key: password 19 roles: 20 - name: root 21 db: admin 22 EOF 23 24 user used by MongoDB Search to connect to MongoDB database to synchronize data from 25 For MongoDB <8.2, the operator will be creating the searchCoordinator custom role automatically 26 From MongoDB 8.2, searchCoordinator role will be a built-in role. 27 kubectl --context "${K8S_CTX}" --namespace "${MDB_NS}" \ 28 create secret generic "${MDB_RESOURCE_NAME}-search-sync-source-password" \ 29 --from-literal=password="${MDB_SEARCH_SYNC_USER_PASSWORD}" 30 kubectl apply --context "${K8S_CTX}" -n "${MDB_NS}" -f - <<EOF 31 apiVersion: mongodb.com/v1 32 kind: MongoDBUser 33 metadata: 34 name: search-sync-source-user 35 spec: 36 username: search-sync-source 37 db: admin 38 mongodbResourceRef: 39 name: ${MDB_RESOURCE_NAME} 40 passwordSecretKeyRef: 41 name: ${MDB_RESOURCE_NAME}-search-sync-source-password 42 key: password 43 roles: 44 - name: searchCoordinator 45 db: admin 46 EOF 47 48 user performing search queries 49 kubectl --context "${K8S_CTX}" --namespace "${MDB_NS}" \ 50 create secret generic mdb-user-password \ 51 --from-literal=password="${MDB_USER_PASSWORD}" 52 kubectl apply --context "${K8S_CTX}" -n "${MDB_NS}" -f - <<EOF 53 apiVersion: mongodb.com/v1 54 kind: MongoDBUser 55 metadata: 56 name: mdb-user 57 spec: 58 username: mdb-user 59 db: admin 60 mongodbResourceRef: 61 name: ${MDB_RESOURCE_NAME} 62 passwordSecretKeyRef: 63 name: mdb-user-password 64 key: password 65 roles: 66 - name: readWrite 67 db: sample_mflix 68 EOF
1 secret/mdb-admin-user-password created 2 secret/mdbc-rs-search-sync-source-password created 3 secret/mdb-user-password created
Obrigatório. Crie e implemente o recurso para MongoDB Search e Vector Search.
Você pode implementar uma instância do nó de pesquisa sem nenhum balanceamento de carga. Para implantar, conclua as seguintes etapas:
Crie um recurso personalizado do MongoDBSearch denominado
mdbc-rs.Este recurso especifica os requisitos de recursos de CPU e memória para os nós de pesquisa. Para saber mais sobre as configurações neste recurso personalizado, consulte Configurações de pesquisa do MongoDB e Vector Search.
1 kubectl apply --context "${K8S_CTX}" -n "${MDB_NS}" -f - <<EOF 2 apiVersion: mongodb.com/v1 3 kind: MongoDBSearch 4 metadata: 5 name: ${MDB_RESOURCE_NAME} 6 spec: 7 no need to specify source.mongodbResourceRef if MongoDBSearch CR has the same name as MongoDB CR 8 the operator infer it automatically 9 security: 10 tls: 11 certificateKeySecretRef: 12 name: ${MDB_SEARCH_TLS_SECRET_NAME} 13 resourceRequirements: 14 limits: 15 cpu: "3" 16 memory: 5Gi 17 requests: 18 cpu: "2" 19 memory: 3Gi 20 EOF Aguarde a conclusão do sistema do recurso MongoDBSearch.
Quando você aplica o recurso personalizado MongoDBSearch, o operador Kubernetes começa a implantar os nós de pesquisa (pods). Essa etapa pausa a execução até que a fase de status do recurso
mdbc-rssejaRunning, o que indica que o conjunto de réplicas da MongoDB Community está operacional.1 echo "Waiting for MongoDBSearch resource to reach Running phase..." 2 kubectl --context "${K8S_CTX}" -n "${MDB_NS}" wait --for=jsonpath='{.status.phase}'=Running "mdbs/${MDB_RESOURCE_NAME}" --timeout=300s
Opcional. Verifique o status do recurso MongoDB Enterprise .
Certifique-se de que a implementação do recurso MongoDB com o MongoDBSearch tenha sido bem-sucedida.
1 echo "Waiting for MongoDB resource to reach Running phase..." 2 kubectl --context "${K8S_CTX}" -n "${MDB_NS}" wait --for=jsonpath='{.status.phase}'=Running "mdb/${MDB_RESOURCE_NAME}" --timeout=400s
Opcional. Visualize todos os pods em execução em seu namespace.
Visualize todos os pods em execução nos pods do seu namespace para os nós do conjunto de réplicas do MongoDB , o operador do MongoDB Controladores for Kubernetes e os nós de pesquisa.
1 echo; echo "MongoDB resource" 2 kubectl --context "${K8S_CTX}" -n "${MDB_NS}" get "mdb/${MDB_RESOURCE_NAME}" 3 echo; echo "MongoDBSearch resource" 4 kubectl --context "${K8S_CTX}" -n "${MDB_NS}" get "mdbs/${MDB_RESOURCE_NAME}" 5 echo; echo "Pods running in cluster ${K8S_CTX}" 6 kubectl --context "${K8S_CTX}" -n "${MDB_NS}" get pods
1 MongoDB resource 2 NAME PHASE VERSION TYPE AGE 3 mdb-rs Running 8.2.0-ent ReplicaSet 6m19s 4 5 MongoDBSearch resource 6 NAME PHASE VERSION AGE 7 mdb-rs Running 0.55.0 3m39s 8 9 Pods running in cluster kind-kind 10 NAME READY STATUS RESTARTS AGE 11 mdb-rs-0 1/1 Running 0 6m17s 12 mdb-rs-1 1/1 Running 0 5m24s 13 mdb-rs-2 1/1 Running 0 4m44s 14 mdb-rs-search-0 1/1 Running 3 (2m58s ago) 3m39s 15 mongodb-kubernetes-operator-7bd6cdd889-9p7cx 1/1 Running 0 6m37s
Próximos passos
Agora que implementou com sucesso o MongoDB Search e o Vector Search para usar com o MongoDB Enterprise Edition, você pode adicionar dados em seu cluster do MongoDB , criar índices do MongoDB Search e Vector Search e executar queries em seus dados. Para saber mais, consulte Configurações do MongoDB Search e Vector Search.