对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

将外部应用程序数据库返回Ops Manager

您可以通过Ops Manager资源将外部应用程序数据库返回内部管理。 Ops Manager资源回收现有的应用程序数据库 StatefulSet,然后您删除托管它的MongoDB资源。 Kubernetes Operator 不会移动或重新创建数据,也不会重启Ops Manager Pod。

The Ops Manager resource starts with an external Application Database: a MongoDB resource with spec.role set to AppDB, named <primary-om-name>-db, that owns the Application Database StatefulSet. The migration proceeds as follows:

  1. You remove spec.externalApplicationDatabaseRef from the Ops Manager resource and add spec.applicationDatabase.

  2. The Kubernetes Operator asks the MongoDB resource to release the StatefulSet. The MongoDB resource reports the Pending phase while it waits for the Ops Manager resource to reclaim it.

  3. Kubernetes Operator 回收 StatefulSet 并将其作为内部应用程序数据库进行管理。由于连接字符串未更改,因此Ops Manager Pod 不会重新启动。

  4. 您删除了MongoDB资源,该资源不再拥有任何内容。

警告

Delete the MongoDB resource only after the Ops Manager resource manages the internal Application Database again. If you delete the MongoDB resource while it still owns the StatefulSet, Kubernetes garbage collects the Application Database. Recovering from that state requires recreating the Application Database from the retained Persistent Volume Claims, which causes downtime and rotates the Application Database credentials.

在开始之前,请完成以下任务:

  • Install the Kubernetes Operator and kubectl. To learn more, see Install with Kubernetes.

  • Confirm that the primary Ops Manager resource uses an external Application Database: it sets spec.externalApplicationDatabaseRef to a MongoDB resource named <primary-om-name>-db, it doesn't set spec.applicationDatabase, and its status.applicationDatabase.phase reports Disabled.

  • Confirm that the MongoDB resource is in the Running phase and owns the Application Database StatefulSet.

在迁移之前,请查看以下注意事项:

  • Set spec.applicationDatabase.version to the version that the Application Database already runs. Reusing the same version keeps the same binaries and data in place. A different version starts an Application Database upgrade at the same time as the handover.

  • Kubernetes Operator 不会删除为外部应用程序数据库创建的Ops Manager项目。删除该项目会使应用程序数据库的历史指标无法读取,因此您可以决定是否清理该项目。

1
export K8S_CTX="<your-kube-context>"
export MDB_NS="mongodb"
export PRIMARY_OM_NAME="primary-om"
export APPDB_NAME="${PRIMARY_OM_NAME}-db"
export APPDB_VERSION="8.0.5-ent"
2
  1. Confirm that the Ops Manager resource references the external Application Database and reports its Application Database as Disabled:

    kubectl get om "${PRIMARY_OM_NAME}" --context "${K8S_CTX}" -n "${MDB_NS}" \
    -o jsonpath='ref={.spec.externalApplicationDatabaseRef.name} appdb={.status.applicationDatabase.phase}{"\n"}'
  2. 确认MongoDB资源拥有应用程序数据库 StatefulSet:

    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}.

3

This patch removes spec.externalApplicationDatabaseRef and adds spec.applicationDatabase.

kubectl patch om "${PRIMARY_OM_NAME}" \
--context "${K8S_CTX}" -n "${MDB_NS}" \
--type merge \
-p "{\"spec\":{\"externalApplicationDatabaseRef\":null,\"applicationDatabase\":{\"members\":3,\"version\":\"${APPDB_VERSION}\"}}}"
4
  1. Confirm that the MongoDB resource releases the StatefulSet. The resource reports the Pending phase with a message that it is under reverse migration to the Ops Manager resource:

    kubectl wait --for=jsonpath='{.status.phase}'=Pending \
    mdb/"${APPDB_NAME}" --context "${K8S_CTX}" -n "${MDB_NS}" --timeout=300s
    kubectl get mdb "${APPDB_NAME}" --context "${K8S_CTX}" -n "${MDB_NS}" \
    -o jsonpath='{.status.message}{"\n"}'
  2. 等待Ops Manager资源再次管理内部应用程序数据库:

    kubectl wait --for=jsonpath='{.status.applicationDatabase.phase}'=Running \
    om/"${PRIMARY_OM_NAME}" --context "${K8S_CTX}" -n "${MDB_NS}" --timeout=1200s
    kubectl wait --for=jsonpath='{.status.opsManager.phase}'=Running \
    om/"${PRIMARY_OM_NAME}" --context "${K8S_CTX}" -n "${MDB_NS}" --timeout=1800s
5

Complete this step only after the previous step reports applicationDatabase.phase=Running.

kubectl delete mdb "${APPDB_NAME}" \
--context "${K8S_CTX}" -n "${MDB_NS}" --wait=true --timeout=300s
6
  1. 确认Ops Manager资源拥有应用程序数据库 StatefulSet:

    kubectl get statefulset "${APPDB_NAME}" --context "${K8S_CTX}" -n "${MDB_NS}" \
    -o jsonpath='{range .metadata.ownerReferences[*]}{.kind}/{.name}{"\n"}{end}'

    The command returns MongoDBOpsManager/${PRIMARY_OM_NAME}.

  2. Confirm that the Ops Manager resource reports its Application Database as Running and that the MongoDB resource no longer exists:

    kubectl get om "${PRIMARY_OM_NAME}" --context "${K8S_CTX}" -n "${MDB_NS}" \
    -o jsonpath='{.status.applicationDatabase.phase}{"\n"}'
    kubectl get mdb --context "${K8S_CTX}" -n "${MDB_NS}"
  3. 检查 Ops Manager Pod 的期限和重启次数,确认Ops Manager Pod 没有重启:

    kubectl get pods --context "${K8S_CTX}" -n "${MDB_NS}"

If the MongoDB resource stays in the Running phase and still owns the StatefulSet, the Ops Manager resource hasn't requested the release. Confirm that your patch set spec.externalApplicationDatabaseRef to null and added spec.applicationDatabase.

Set spec.applicationDatabase.version to the version that the Application Database already runs so that the reclaimed StatefulSet keeps the same binaries.

If you delete the MongoDB resource while it still owns the StatefulSet, Kubernetes garbage collects the StatefulSet and the secrets that it shares with the Ops Manager resource. To recover, recreate the Application Database from the retained Persistent Volume Claims. This path causes downtime and rotates the Application Database credentials. To learn more, see Disaster Recovery for Ops Manager and AppDB Resources.

To use an external Application Database again, see Migrate an Application Database to an External Deployment.