You can deploy an Ops Manager resource that uses an external Application Database: a MongoDB custom resource with spec.role set to AppDB, which a second Ops Manager instance manages as a project. This lets Ops Manager back up and restore the Application Database. To learn more, see Back Up the Ops Manager Application Database.
This procedure deploys a new Ops Manager instance. To convert an existing Ops Manager instance that uses an internally managed Application Database, see Migrate an Application Database to an External Deployment.
此过程将部署以下资源:
具有自己的内部托管的应用程序数据库的管理Ops Manager实例。此实例管理包含外部应用程序数据库的项目。
An external Application Database: a MongoDB replica set with
spec.roleset toAppDB, named<primary-om-name>-db.A primary Ops Manager instance that omits
spec.applicationDatabaseand references the external Application Database withspec.externalApplicationDatabaseRef.
先决条件
在开始之前,请完成以下任务:
Deploy a Kubernetes cluster with a default
StorageClass.Install
kubectlandhelmand configure them for that cluster.获取Kubernetes Operator Helm 图表的访问权限。
Considerations
将Ops Manager版本和应用程序数据库版本设置为一致对。管理Ops Manager实例管理外部应用程序数据库,因此应用程序数据库版本必须是管理Ops Manager实例在其版本清单中提供的MongoDB版本。示例,8.0.x Ops Manager实例提供 8.0.x MongoDB版本,但 7.0.x Ops Manager实例不提供。
步骤
为部署设置环境变量。
export K8S_CTX="<your-kube-context>" export MDB_NS="mongodb" export OPERATOR_HELM_CHART="oci://quay.io/mongodb/helm-charts/mongodb-kubernetes" export OM_VERSION="8.0.7" export APPDB_VERSION="8.0.5-ent" export MANAGEMENT_OM_NAME="management-om" export PRIMARY_OM_NAME="primary-om" export APPDB_NAME="${PRIMARY_OM_NAME}-db" export MANAGEMENT_OM_URL="http://${MANAGEMENT_OM_NAME}-svc.${MDB_NS}.svc.cluster.local:8080" export MANAGEMENT_OM_ADMIN_KEY_SECRET="${MDB_NS}-${MANAGEMENT_OM_NAME}-admin-key" export APPDB_PROJECT_CONFIGMAP="${APPDB_NAME}-config" export APPDB_PROJECT_NAME="external-appdb" export APPDB_CONNECTION_STRING_SECRET="${APPDB_NAME}-connection-string" export OM_ADMIN_EMAIL="admin@example.com" export OM_ADMIN_PASSWORD="<your-password>" export OM_ADMIN_FIRST_NAME="Admin" export OM_ADMIN_LAST_NAME="User"
The Kubernetes Operator requires the external Application Database to be named <primary-om-name>-db, which is why APPDB_NAME derives from PRIMARY_OM_NAME.
创建Ops Manager管理员密钥。
Both Ops Manager resources reference this secret with spec.adminCredentials.
kubectl create secret generic ops-manager-admin-secret \ --context "${K8S_CTX}" -n "${MDB_NS}" \ --from-literal=Username="${OM_ADMIN_EMAIL}" \ --from-literal=Password="${OM_ADMIN_PASSWORD}" \ --from-literal=FirstName="${OM_ADMIN_FIRST_NAME}" \ --from-literal=LastName="${OM_ADMIN_LAST_NAME}"
部署管理Ops Manager实例。
kubectl apply --context "${K8S_CTX}" -n "${MDB_NS}" -f - <<EOF apiVersion: mongodb.com/v1 kind: MongoDBOpsManager metadata: name: ${MANAGEMENT_OM_NAME} spec: replicas: 1 version: ${OM_VERSION} adminCredentials: ops-manager-admin-secret applicationDatabase: members: 3 version: ${APPDB_VERSION} backup: enabled: false configuration: automation.versions.source: mongodb mms.ignoreInitialUiSetup: "true" mms.adminEmailAddr: admin@example.com mms.fromEmailAddr: admin@example.com mms.replyToEmailAddr: admin@example.com mms.mail.hostname: email-smtp.us-east-1.amazonaws.com mms.mail.port: "465" mms.mail.ssl: "true" mms.mail.transport: smtp mms.minimumTLSVersion: TLSv1.2 EOF
The mms.* mail settings are required. When mms.ignoreInitialUiSetup is true, the Ops Manager pre-flight check doesn't start Ops Manager unless mms.fromEmailAddr and the related mail settings are present.
等待管理Ops Manager实例准备就绪。
等待内部托管的应用程序数据库和Ops Manager资源:
kubectl wait --for=jsonpath='{.status.applicationDatabase.phase}'=Running \ om/"${MANAGEMENT_OM_NAME}" --context "${K8S_CTX}" -n "${MDB_NS}" --timeout=1200s kubectl wait --for=jsonpath='{.status.opsManager.phase}'=Running \ om/"${MANAGEMENT_OM_NAME}" --context "${K8S_CTX}" -n "${MDB_NS}" --timeout=1800s Confirm that the Ops Manager public API answers requests. An
opsManager.phaseofRunningmeans that the Ops Manager pod is up, but the API that the Kubernetes Operator uses to create the Application Database project can lag by a few seconds. A401response is the expected unauthenticated response and means that the API is ready:om_pod="${MANAGEMENT_OM_NAME}-0" until [ "$(kubectl exec "${om_pod}" -c mongodb-ops-manager --context "${K8S_CTX}" -n "${MDB_NS}" -- \ curl -s -o /dev/null -w '%{http_code}' \ "http://$(kubectl get pod "${om_pod}" --context "${K8S_CTX}" -n "${MDB_NS}" \ -o jsonpath='{.status.podIP}'):8080/api/public/v1.0" 2>/dev/null)" = "401" ]; do echo "waiting for management Ops Manager public API..."; sleep 10 done Confirm that the Kubernetes Operator created the programmatic API key secret for the management Ops Manager instance:
kubectl get secret "${MANAGEMENT_OM_ADMIN_KEY_SECRET}" \ --context "${K8S_CTX}" -n "${MDB_NS}"
创建外部应用程序数据库。
kubectl apply --context "${K8S_CTX}" -n "${MDB_NS}" -f - <<EOF apiVersion: mongodb.com/v1 kind: MongoDB metadata: name: ${APPDB_NAME} spec: members: 3 version: ${APPDB_VERSION} type: ReplicaSet role: AppDB opsManager: configMapRef: name: ${APPDB_PROJECT_CONFIGMAP} credentials: ${MANAGEMENT_OM_ADMIN_KEY_SECRET} persistent: true EOF kubectl wait --for=jsonpath='{.status.phase}'=Running \ mdb/"${APPDB_NAME}" --context "${K8S_CTX}" -n "${MDB_NS}" --timeout=1200s
When you set spec.role to AppDB, the Kubernetes Operator configures SCRAM authentication for the resource. To learn more, see spec.role.
部署Ops Manager主节点 (primary node in the replica set)实例。
This resource omits spec.applicationDatabase and references the external Application Database instead.
kubectl apply --context "${K8S_CTX}" -n "${MDB_NS}" -f - <<EOF apiVersion: mongodb.com/v1 kind: MongoDBOpsManager metadata: name: ${PRIMARY_OM_NAME} spec: replicas: 1 version: ${OM_VERSION} adminCredentials: ops-manager-admin-secret externalApplicationDatabaseRef: name: ${APPDB_NAME} kind: MongoDB backup: enabled: false configuration: automation.versions.source: mongodb mms.ignoreInitialUiSetup: "true" mms.adminEmailAddr: admin@example.com mms.fromEmailAddr: admin@example.com mms.replyToEmailAddr: admin@example.com mms.mail.hostname: email-smtp.us-east-1.amazonaws.com mms.mail.port: "465" mms.mail.ssl: "true" mms.mail.transport: smtp mms.minimumTLSVersion: TLSv1.2 EOF
To enable backup for your MongoDB deployments, set spec.backup.enabled to true on this resource and configure snapshot storage. To learn more, see Configure File System Backup Store with Kubernetes Operator.
等待主节点 (primary node in the replica set)Ops Manager实例准备就绪。
kubectl wait --for=jsonpath='{.status.opsManager.phase}'=Running \ om/"${PRIMARY_OM_NAME}" --context "${K8S_CTX}" -n "${MDB_NS}" --timeout=1800s kubectl wait --for=jsonpath='{.status.applicationDatabase.phase}'=Disabled \ om/"${PRIMARY_OM_NAME}" --context "${K8S_CTX}" -n "${MDB_NS}" --timeout=600s
The Kubernetes Operator doesn't manage an internal Application Database for an Ops Manager resource that uses an external Application Database, so status.applicationDatabase.phase reports Disabled. This is expected and isn't an error.
验证部署。
确认管理Ops Manager Pod、外部应用程序数据库 Pod 和主节点 (primary node in the replica set)Ops Manager Pod 正在运行:
kubectl get pods --context "${K8S_CTX}" -n "${MDB_NS}" 确认MongoDB资源拥有应用程序数据库 StatefulSet,并且主节点 (primary node in the replica set)Ops Manager资源不拥有:
kubectl get statefulset "${APPDB_NAME}" --context "${K8S_CTX}" -n "${MDB_NS}" \ -o jsonpath='{range .metadata.ownerReferences[*]}{.kind}/{.name}{"\n"}{end}' The command returns
MongoDB/${APPDB_NAME}.确认Kubernetes Operator主节点 (primary node in the replica set)Ops Manager实例创建连接字符串密钥:
kubectl get secret "${APPDB_CONNECTION_STRING_SECRET}" \ --context "${K8S_CTX}" -n "${MDB_NS}"
常见外部应用程序数据库问题
MongoDB资源报告版本错误
If the external Application Database reports Failed with a message that the MongoDB version isn't available, set spec.version to a version that the management Ops Manager instance offers. Keep the Ops Manager version and the Application Database version on the same major version. The management Ops Manager instance's own internally managed Application Database isn't affected, because it downloads binaries directly when you set automation.versions.source to mongodb.
外部应用程序数据库保持待处理状态
If the external Application Database stays in the Pending phase and the MongoDB Agent never receives an automation configuration, you might have created the MongoDB resource before the management Ops Manager public API was serving requests. The Kubernetes Operator couldn't create the project. Confirm that the API readiness check returns 401, then reconcile the resource again.
Operator 拒绝外部应用程序数据库引用
The value of spec.externalApplicationDatabaseRef.name must be exactly <primary-om-name>-db, and the MongoDB resource must be in the same namespace as the Ops Manager resource.
后续步骤
To back up the external Application Database, enable backup on the MongoDB resource in the project that the management Ops Manager instance manages. To learn more, see Configure MongoDB Database Backups.