AI 에이전트의 경우: 문서 인덱스는 https://www.mongodb.com/ko-kr/docs/llms.txt에서 사용할 수 있으며, 모든 페이지의 마크다운 버전은 어떤 URL 경로에 .md를 추가하여 사용할 수 있습니다.

MongoDB 엔터프라이즈 로 검색 설치 및 사용

Kubernetes 연산자를 사용하여 MongoDB Search 및 벡터 검색 리소스를 배포하여 Kubernetes 클러스터에서 MongoDB Enterprise v8.2.0 이상으로 실행할 수 있습니다. 이 절차에서는 Kubernetes 클러스터의 신규 또는 기존 복제본 세트와 함께 실행하도록 mongot 프로세스를 배포하고 구성하는 방법을 보여 줍니다. 배포서버 TLS 인증서를 사용하여 MongoDB 노드와 mongot 검색 프로세스 간의 보안 통신을 보장합니다.

MongoDB Search 및 Vector Search를 배포 하려면 다음이 필요합니다.

  • 로컬에서 사용할 수 있는 kubeconfig 가 포함 실행 Kubernetes 클러스터 입니다.

  • Kubernetes 명령줄 도구인 kubectl이(가) 클러스터 와 통신하도록 구성되었습니다.

  • 이 튜토리얼의 명령을 실행 하려면 Bash v5.1 이상을 사용해야 합니다.

  • MongoDB Ops Manager 또는 MongoDB Cloud Manager 프로젝트 및 API 자격 증명.

1

이 절차의 후속 단계에서 사용할 환경 변수를 설정합니다. 다음 명령을 복사하여 환경에 맞는 값을 업데이트 다음, 이를 실행 변수를 로드합니다.

# set it to the context name of the k8s clusterexport K8S_CTX="<local cluster context>" # the following namespace will be created if not existsexport MDB_NS="mongodb" # name of the MongoDB Custom Resource.export MDB_RESOURCE_NAME="mdb-rs" export MDB_MEMBERS=3# OM/CM's project name to be used to manage mongodb replica setexport OPS_MANAGER_PROJECT_NAME="<arbitrary project name>" # URL to Cloud Manager or Ops Manager instanceexport OPS_MANAGER_API_URL="https://cloud-qa.mongodb.com" # The API key can be an Org Owner - the operator can create the project automatically then.# The API key can also be created in a particular project that was created manually with the Project Owner scope.export OPS_MANAGER_API_USER="<SET API USER>"export OPS_MANAGER_API_KEY="<SET API KEY>"export OPS_MANAGER_ORG_ID="<SET ORG ID>" # minimum required MongoDB version for running MongoDB Search is 8.2.0export MDB_VERSION="8.2.0-ent" # root admin user for convenience, not used here at all in this guideexport MDB_ADMIN_USER_PASSWORD="admin-user-password-CHANGE-ME"# regular user performing restore and search queries on sample mflix databaseexport MDB_USER_PASSWORD="mdb-user-password-CHANGE-ME"# user for MongoDB Search to connect to the replica set to synchronise data fromexport MDB_SEARCH_SYNC_USER_PASSWORD="search-sync-user-password-CHANGE-ME" export OPERATOR_HELM_CHART="mongodb/mongodb-kubernetes"# comma-separated key=value pairs for additional parameters passed to the helm-chart installing the operatorexport OPERATOR_ADDITIONAL_HELM_VALUES="" export MDB_TLS_CERT_SECRET_PREFIX="certs"export MDB_TLS_CA_CONFIGMAP="${MDB_RESOURCE_NAME}-ca-configmap" export CERT_MANAGER_NAMESPACE="cert-manager"export MDB_TLS_SELF_SIGNED_ISSUER="selfsigned-bootstrap-issuer"export MDB_TLS_CA_CERT_NAME="my-selfsigned-ca"export MDB_TLS_CA_SECRET_NAME="root-secret"export MDB_TLS_CA_ISSUER="my-ca-issuer"export MDB_TLS_SERVER_CERT_SECRET_NAME="${MDB_TLS_CERT_SECRET_PREFIX}-${MDB_RESOURCE_NAME}-cert"export MDB_SEARCH_TLS_SECRET_NAME="${MDB_RESOURCE_NAME}-search-tls" 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"
2

Helm 은 Kubernetes 에서 MongoDB 인스턴스의 배포서버 및 관리 자동화합니다. Kubernetes Operator 연산자 설치를 위한 Helm 차트 포함된 Helm 리포지토리 이미 추가한 경우 이 단계를 건너뜁니다. 그렇지 않으면 Helm 리포지토리 추가합니다.

다음 명령을 추가, 복사, 붙여넣기 및 실행 하려면 다음을 수행하세요.

helm repo add mongodb https://mongodb.github.io/helm-chartshelm repo update mongodbhelm search repo mongodb/mongodb-kubernetes
3

Kubernetes Operator는 MongoDB, MongoDBOpsManager 및 MongoDBSearch 사용자 지정 리소스를 감시하고 MongoDB deployment의 수명 주기를 관리합니다. Kubernetes 연산자용 MongoDB 컨트롤러를 이미 설치한 경우 이 단계를 건너뛰세요. 그렇지 않으면 이전 단계에서 추가한 Helm 리포지토리 에서 Kubernetes 연산자용 MongoDB 컨트롤러를 설치합니다.

mongodb 네임스페이스 에 Kubernetes Operator용 MongoDB 컨트롤러를 설치하려면 다음을 복사하여 붙여넣고 실행 .

helm upgrade --install --debug --kube-context "${K8S_CTX}" \ --create-namespace \ --namespace="${MDB_NS}" \ mongodb-kubernetes \ ${OPERATOR_ADDITIONAL_HELM_VALUES:+--set ${OPERATOR_ADDITIONAL_HELM_VALUES}} \ "${OPERATOR_HELM_CHART}"
4

TLS 인증서를 관리하려면 cert-manager 이(가) 필요합니다. 클러스터 에 cert-manager 가 이미 설치되어 있는 경우 이 단계를 건너뛰세요. 그렇지 않으면 Helm을 사용하여 cert-manager 를 설치합니다.

cert-manager 네임스페이스 에 cert-manager 를 설치하려면 터미널에서 다음 명령을 실행 .

helm upgrade --install \ cert-manager \ oci://quay.io/jetstack/charts/cert-manager \ --kube-context "${K8S_CTX}" \ --namespace "${CERT_MANAGER_NAMESPACE}" \ --create-namespace \ --set crds.enabled=true for deployment in cert-manager cert-manager-cainjector cert-manager-webhook; do kubectl --context "${K8S_CTX}" \ -n "${CERT_MANAGER_NAMESPACE}" \ wait --for=condition=Available "deployment/${deployment}" --timeout=300sdone echo "cert-manager is ready in namespace ${CERT_MANAGER_NAMESPACE}."
5

MongoDB 및 MongoDBSearch 리소스에 대한 TLS 인증서를 발급할 인증 기관 인프라를 생성합니다. 이러한 명령은 다음 조치를 수행합니다.

  • 자체 서명된 ClusterIssuer을 만듭니다.

  • CA 인증서를 생성합니다.

  • 모든 네임스페이스가 사용할 수 있는 클러스터 전체 CA 발급자를 게시합니다.

  • MongoDB 리소스가 사용할 수 있도록 ConfigMap 를 통해 CA 번들을 노출합니다.

# Bootstrap a self-signed ClusterIssuer to mint the CA secret consumed by application workloads.kubectl apply --context "${K8S_CTX}" -f - <<EOF_MANIFESTapiVersion: cert-manager.io/v1kind: ClusterIssuermetadata: name: ${MDB_TLS_SELF_SIGNED_ISSUER}spec: selfSigned: {}EOF_MANIFEST kubectl --context "${K8S_CTX}" wait --for=condition=Ready clusterissuer "${MDB_TLS_SELF_SIGNED_ISSUER}" kubectl apply --context "${K8S_CTX}" -f - <<EOF_MANIFESTapiVersion: cert-manager.io/v1kind: Certificatemetadata: name: ${MDB_TLS_CA_CERT_NAME} namespace: ${CERT_MANAGER_NAMESPACE}spec: isCA: true commonName: ${MDB_TLS_CA_CERT_NAME} secretName: ${MDB_TLS_CA_SECRET_NAME} privateKey: algorithm: ECDSA size: 256 issuerRef: name: ${MDB_TLS_SELF_SIGNED_ISSUER} kind: ClusterIssuerEOF_MANIFEST kubectl --context "${K8S_CTX}" wait --for=condition=Ready -n "${CERT_MANAGER_NAMESPACE}" certificate "${MDB_TLS_CA_CERT_NAME}" kubectl apply --context "${K8S_CTX}" -f - <<EOF_MANIFESTapiVersion: cert-manager.io/v1kind: ClusterIssuermetadata: name: ${MDB_TLS_CA_ISSUER}spec: ca: secretName: ${MDB_TLS_CA_SECRET_NAME}EOF_MANIFEST kubectl --context "${K8S_CTX}" wait --for=condition=Ready clusterissuer "${MDB_TLS_CA_ISSUER}" TMP_CA_CERT="$(mktemp)"trap 'rm -f "${TMP_CA_CERT}"' EXIT 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}" kubectl --context "${K8S_CTX}" create configmap "${MDB_TLS_CA_CONFIGMAP}" -n "${MDB_NS}" \ --from-file=ca-pem="${TMP_CA_CERT}" --from-file=mms-ca.crt="${TMP_CA_CERT}" \ --from-file=ca.crt="${TMP_CA_CERT}" \ --dry-run=client -o yaml | kubectl --context "${K8S_CTX}" apply -f -
6

MongoDB 서버(${MDB_RESOURCE_NAME}-server-tls)와 MongoDBSearch 서비스(${MDB_RESOURCE_NAME}-search-tls) 모두에 대한 TLS 인증서를 발급합니다. MongoDB 서버 인증서에는 pod 및 서비스 통신을 위한 필요한 모든 DNS 이름이 포함되어 있습니다. 두 인증서 모두 서버 및 클라이언트 인증을 지원합니다.

server_certificate="${MDB_RESOURCE_NAME}-server-tls"search_certificate="${MDB_RESOURCE_NAME}-search-tls" mongo_dns_names=()for ((member = 0; member < MDB_MEMBERS; member++)); do mongo_dns_names+=("${MDB_RESOURCE_NAME}-${member}") mongo_dns_names+=("${MDB_RESOURCE_NAME}-${member}.${MDB_RESOURCE_NAME}-svc.${MDB_NS}.svc.cluster.local")donemongo_dns_names+=( "${MDB_RESOURCE_NAME}-svc.${MDB_NS}.svc.cluster.local" "*.${MDB_RESOURCE_NAME}-svc.${MDB_NS}.svc.cluster.local") search_dns_names=( "${MDB_RESOURCE_NAME}-search-svc.${MDB_NS}.svc.cluster.local") render_dns_list() { local dns_list=("$@") for dns in "${dns_list[@]}"; do printf " - \"%s\"\n" "${dns}" done} kubectl apply --context "${K8S_CTX}" -n "${MDB_NS}" -f - <<EOF_MANIFESTapiVersion: cert-manager.io/v1kind: Certificatemetadata: name: ${server_certificate} namespace: ${MDB_NS}spec: secretName: ${MDB_TLS_SERVER_CERT_SECRET_NAME} issuerRef: name: ${MDB_TLS_CA_ISSUER} kind: ClusterIssuer duration: 240h0m0s renewBefore: 120h0m0s usages: - digital signature - key encipherment - server auth - client auth dnsNames:$(render_dns_list "${mongo_dns_names[@]}")---apiVersion: cert-manager.io/v1kind: Certificatemetadata: name: ${search_certificate} namespace: ${MDB_NS}spec: secretName: ${MDB_SEARCH_TLS_SECRET_NAME} issuerRef: name: ${MDB_TLS_CA_ISSUER} kind: ClusterIssuer duration: 240h0m0s renewBefore: 120h0m0s usages: - digital signature - key encipherment - server auth - client auth dnsNames:$(render_dns_list "${search_dns_names[@]}")EOF_MANIFEST kubectl --context "${K8S_CTX}" -n "${MDB_NS}" wait --for=condition=Ready certificate "${server_certificate}" --timeout=300skubectl --context "${K8S_CTX}" -n "${MDB_NS}" wait --for=condition=Ready certificate "${search_certificate}" --timeout=300s
7

이미 MongoDB 엔터프라이즈 배포한 경우 다음 단계로 건너뜁니다. 그렇지 않으면 MongoDB 엔터프라이즈 리소스 배포 .

MongoDB 엔터프라이즈 배포 하려면 다음 단계를 완료하세요.

  1. MongoDB Ops Manager 사용하는 경우 MongoDB Ops Manager 프로젝트 대한 ConfigMap 및 시크릿을 생성합니다.

    MongoDB Ops Manager 통합을 위한 구성 및 자격 증명 저장 하려면 다음 명령을 복사하여 붙여넣고 실행.

    kubectl --context "${K8S_CTX}" -n "${MDB_NS}" create configmap om-project \ --from-literal=projectName="${OPS_MANAGER_PROJECT_NAME}" --from-literal=baseUrl="${OPS_MANAGER_API_URL}" \ --from-literal=orgId="${OPS_MANAGER_ORG_ID:-}" kubectl --context "${K8S_CTX}" -n "${MDB_NS}" create secret generic om-credentials \ --from-literal=publicKey="${OPS_MANAGER_API_USER}" \ --from-literal=privateKey="${OPS_MANAGER_API_KEY}"
  2. mdb-rs(이)라는 MongoDB 사용자 지정 리소스 만듭니다.

    리소스 mongod 및 mongodb-agent 컨테이너의 CPU 및 메모리 리소스를 정의하고 Kubernetes Operator에게 3 멤버로 MongoDB 복제본 세트 구성하도록 지시합니다.

    MongoDB 엔터프라이즈 배포 하려면 네임스페이스 에서 다음을 복사하여 붙여넣고 실행 .

    kubectl apply --context "${K8S_CTX}" -n "${MDB_NS}" -f - <<EOFapiVersion: mongodb.com/v1kind: MongoDBmetadata: name: ${MDB_RESOURCE_NAME}spec: members: ${MDB_MEMBERS} version: ${MDB_VERSION} type: ReplicaSet opsManager: configMapRef: name: om-project credentials: om-credentials security: authentication: enabled: true ignoreUnknownUsers: true modes: - SCRAM certsSecretPrefix: ${MDB_TLS_CERT_SECRET_PREFIX} tls: enabled: true ca: ${MDB_TLS_CA_CONFIGMAP} agent: logLevel: INFO podSpec: podTemplate: spec: containers: - name: mongodb-enterprise-database resources: limits: cpu: "2" memory: 2Gi requests: cpu: "1" memory: 1GiEOF
  3. MongoDB 리소스 배포서버 완료될 때까지 기다립니다.

    MongoDB 사용자 지정 리소스 적용 Kubernetes 연산자 MongoDB 노드(포드) 배포를 시작합니다. 이 단계에서는 mdbc-rs 리소스의 상태 단계가 Running가 되어 MongoDB Community 복제본 세트 작동 가능함을 나타낼 때까지 실행을 일시 중지합니다.

    echo "Waiting for MongoDB resource to reach Running phase..."kubectl --context "${K8S_CTX}" -n "${MDB_NS}" wait --for=jsonpath='{.status.phase}'=Running "mdb/${MDB_RESOURCE_NAME}" --timeout=400secho; echo "MongoDB resource"kubectl --context "${K8S_CTX}" -n "${MDB_NS}" get "mdb/${MDB_RESOURCE_NAME}"echo; echo "Pods running in cluster ${K8S_CTX}"kubectl --context "${K8S_CTX}" -n "${MDB_NS}" get pods
8

MongoDB 보안 액세스 위해 인증 필요합니다. 이 단계에서는 세 개의 Kubernetes 시크릿을 생성합니다.

  • mdb-admin-user-password: MongoDB 관리자의 자격 증명입니다.

  • mdb-user-password: 검색 쿼리를 수행할 수 있는 권한이 있는 사용자의 자격 증명입니다.

  • mdbc-rs-search-sync-source-password: mongot 프로세스 에서 데이터를 동기화하고 인덱스를 관리 위해 내부적으로 사용하는 검색 전용 사용자에 대한 자격 증명입니다.

Kubernetes Operator는 이러한 시크릿을 MongoDB pod에 마운트합니다.

시크릿을 생성하려면 MongoDB Server 배포하고 MongoDB Search 및 Vector Search를 배포 하려는 네임스페이스 에 다음을 복사하여 붙여넣은 후 실행 .

# admin user with root rolekubectl --context "${K8S_CTX}" --namespace "${MDB_NS}" \ create secret generic mdb-admin-user-password \ --from-literal=password="${MDB_ADMIN_USER_PASSWORD}" kubectl apply --context "${K8S_CTX}" -n "${MDB_NS}" -f - <<EOFapiVersion: mongodb.com/v1kind: MongoDBUsermetadata: name: mdb-adminspec: username: mdb-admin db: admin mongodbResourceRef: name: ${MDB_RESOURCE_NAME} passwordSecretKeyRef: name: mdb-admin-user-password key: password roles: - name: root db: adminEOF # user used by MongoDB Search to connect to MongoDB database to synchronize data from# For MongoDB <8.2, the operator will be creating the searchCoordinator custom role automatically# From MongoDB 8.2, searchCoordinator role will be a built-in role.kubectl --context "${K8S_CTX}" --namespace "${MDB_NS}" \ create secret generic "${MDB_RESOURCE_NAME}-search-sync-source-password" \ --from-literal=password="${MDB_SEARCH_SYNC_USER_PASSWORD}"kubectl apply --context "${K8S_CTX}" -n "${MDB_NS}" -f - <<EOFapiVersion: mongodb.com/v1kind: MongoDBUsermetadata: name: search-sync-source-userspec: username: search-sync-source db: admin mongodbResourceRef: name: ${MDB_RESOURCE_NAME} passwordSecretKeyRef: name: ${MDB_RESOURCE_NAME}-search-sync-source-password key: password roles: - name: searchCoordinator db: adminEOF # user performing search querieskubectl --context "${K8S_CTX}" --namespace "${MDB_NS}" \ create secret generic mdb-user-password \ --from-literal=password="${MDB_USER_PASSWORD}"kubectl apply --context "${K8S_CTX}" -n "${MDB_NS}" -f - <<EOFapiVersion: mongodb.com/v1kind: MongoDBUsermetadata: name: mdb-userspec: username: mdb-user db: admin mongodbResourceRef: name: ${MDB_RESOURCE_NAME} passwordSecretKeyRef: name: mdb-user-password key: password roles: - name: readWrite db: sample_mflixEOF
9

로드 밸런싱 없이 검색 노드 의 인스턴스 하나를 배포 할 수 있습니다. 배포 하려면 다음 단계를 완료하세요.

  1. mdbc-rs이라는 이름의 MongoDBSearch 사용자 지정 리소스 만듭니다.

    이 리소스 검색 노드에 대한 CPU 및 메모리 리소스 요구 사항을 지정합니다. 이 사용자 지정 리소스 의 설정에 대해 자세히 학습하려면 MongoDB 검색 및 벡터 검색 설정을 참조하세요.

    kubectl apply --context "${K8S_CTX}" -n "${MDB_NS}" -f - <<EOFapiVersion: mongodb.com/v1kind: MongoDBSearchmetadata: name: ${MDB_RESOURCE_NAME}spec: # no need to specify source.mongodbResourceRef if MongoDBSearch CR has the same name as MongoDB CR # the operator infer it automatically security: tls: certificateKeySecretRef: name: ${MDB_SEARCH_TLS_SECRET_NAME} resourceRequirements: limits: cpu: "3" memory: 5Gi requests: cpu: "2" memory: 3GiEOF
  2. MongoDBSearch 리소스 배포서버 완료될 때까지 기다립니다.

    MongoDBSearch 사용자 지정 리소스 적용 하면 Kubernetes 연산자 검색 노드(pod) 배포를 시작합니다. 이 단계에서는 mdbc-rs 리소스의 상태 단계가 Running이 되어 MongoDB Community 복제본 세트 작동 가능함을 나타낼 때까지 실행을 일시 중지합니다.

    echo "Waiting for MongoDBSearch resource to reach Running phase..."kubectl --context "${K8S_CTX}" -n "${MDB_NS}" wait --for=jsonpath='{.status.phase}'=Running "mdbs/${MDB_RESOURCE_NAME}" --timeout=300s
10

MongoDBSearch를 사용한 MongoDB 리소스 배포서버 성공적인 했는지 확인합니다.

echo "Waiting for MongoDB resource to reach Running phase..."kubectl --context "${K8S_CTX}" -n "${MDB_NS}" wait --for=jsonpath='{.status.phase}'=Running "mdb/${MDB_RESOURCE_NAME}" --timeout=400s
11

네임스페이스 파드에서 MongoDB 복제본 세트 멤버, Kubernetes Operator용 MongoDB 컨트롤러 및 검색 노드에 대해 실행 모든 파드를 확인합니다.

echo; echo "MongoDB resource"kubectl --context "${K8S_CTX}" -n "${MDB_NS}" get "mdb/${MDB_RESOURCE_NAME}"echo; echo "MongoDBSearch resource"kubectl --context "${K8S_CTX}" -n "${MDB_NS}" get "mdbs/${MDB_RESOURCE_NAME}"echo; echo "Pods running in cluster ${K8S_CTX}"kubectl --context "${K8S_CTX}" -n "${MDB_NS}" get pods

이제 MongoDB 엔터프라이즈 와 함께 사용할 MongoDB Search 및 Vector Search를 성공적으로 배포했으므로, MongoDB cluster 에 데이터를 추가하고, MongoDB Search 및 Vector Search 인덱스를 생성하고, 데이터에 대해 쿼리를 실행 . 자세한 학습은 MongoDB 검색 및 벡터 검색 설정을 참조하세요.

이 페이지 평가하기

이 페이지의 내용