您可以通过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:
You remove
spec.externalApplicationDatabaseReffrom the Ops Manager resource and addspec.applicationDatabase.The Kubernetes Operator asks the MongoDB resource to release the StatefulSet. The MongoDB resource reports the
Pendingphase while it waits for the Ops Manager resource to reclaim it.Kubernetes Operator 回收 StatefulSet 并将其作为内部应用程序数据库进行管理。由于连接字符串未更改,因此Ops Manager Pod 不会重新启动。
您删除了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.externalApplicationDatabaseRefto a MongoDB resource named<primary-om-name>-db, it doesn't setspec.applicationDatabase, and itsstatus.applicationDatabase.phasereportsDisabled.Confirm that the MongoDB resource is in the
Runningphase and owns the Application Database StatefulSet.
Considerations
在迁移之前,请查看以下注意事项:
Set
spec.applicationDatabase.versionto 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项目。删除该项目会使应用程序数据库的历史指标无法读取,因此您可以决定是否清理该项目。
步骤
确认起始状态。
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"}' 确认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}.
重新配置Ops Manager资源以使用内部应用程序数据库。
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}\"}}}"
等待Ops Manager资源回收 StatefulSet。
Confirm that the MongoDB resource releases the StatefulSet. The resource reports the
Pendingphase 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"}' 等待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
验证迁移。
确认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}.Confirm that the Ops Manager resource reports its Application Database as
Runningand 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}" 检查 Ops Manager Pod 的期限和重启次数,确认Ops Manager Pod 没有重启:
kubectl get pods --context "${K8S_CTX}" -n "${MDB_NS}"
常见迁移问题
MongoDB资源不释放 StatefulSet
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.
您过早删除了MongoDB资源
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.