You can convert an Ops Manager resource that uses an internally managed Application Database to one that uses an external Application Database: a MongoDB custom resource with spec.role set to AppDB. This lets Ops Manager back up and restore the Application Database. To learn more, see Back Up the Ops Manager Application Database.
The migration re-points ownership of the existing Application Database StatefulSet and its Persistent Volumes from the Ops Manager resource to the MongoDB resource. The Kubernetes Operator doesn't move or recreate your data, and it doesn't restart the Ops Manager pods.
Como funciona a migração
The Ops Manager resource starts with an internally managed Application Database, and the Kubernetes Operator owns a StatefulSet named <primary-om-name>-db. The migration proceeds as follows:
You create a MongoDB resource with
spec.roleset toAppDBand the same name as the StatefulSet, in a project that a management Ops Manager instance manages. The MongoDB resource can't take ownership of the StatefulSet yet, so it stays in thePendingphase with a message that it can't take ownership of the Application Database StatefulSet.You add
spec.externalApplicationDatabaseRefto the Ops Manager resource. The Kubernetes Operator detaches the StatefulSet by removing the Ops Manager resource's owner reference and marking the StatefulSet as ready for migration. The MongoDB resource then takes ownership of it.
Como o Operador Kubernetes calcula a mesma string de conexão de antes, que usa os mesmos nomes de host, os pods do Ops Manager não são reiniciados.
Pré-requisitos
Antes de começar, conclua as seguintes tarefas:
Install the Kubernetes Operator and
kubectl. To learn more, see Install with Kubernetes.Deploy a primary Ops Manager resource that uses an internally managed Application Database. This resource sets
spec.applicationDatabase, and the Kubernetes Operator owns a StatefulSet named<primary-om-name>-db. To learn more, see Deploy an Ops Manager Resource.Deploy a management Ops Manager resource that is in the
Runningphase and that owns the project for the external Application Database. To learn more, see Deploy Ops Manager with an External Application Database.Confirm that the Kubernetes Operator created the programmatic API key secret for the management Ops Manager resource. The Kubernetes Operator names this secret
<namespace>-<management-om-name>-admin-key.
Considerações
Revise as seguintes considerações antes de migrar:
A versão do banco de dados de aplicativos que você define no recurso MongoDB deve corresponder à versão que o banco de dados de aplicativos gerenciado internamente executa e deve ser uma versão do MongoDB que a instância de gerenciamento do Ops Manager oferece.
The Kubernetes Operator doesn't support
spec.applicationDatabase.passwordSecretKeyRefduring migration. The Kubernetes Operator generates a new password, and it rotates any password that you provided.O banco de dados de aplicativos pode ficar indisponível por um a dois minutos se a configuração de recursos do MongoDB for diferente da configuração do banco de dados de aplicativos gerenciado internamente, como um modelo de pod diferente ou um conjunto diferente de contêineres. Se as duas configurações forem semanticamente idênticas, o banco de dados do aplicativo permanecerá disponível.
O Operador Kubernetes suporta migração apenas para um único cluster Kubernetes.
Procedimento
Configure as variáveis de ambiente para a migração.
export K8S_CTX="<your-kube-context>" export MDB_NS="mongodb" export MANAGEMENT_OM_NAME="management-om" export PRIMARY_OM_NAME="primary-om" export APPDB_NAME="${PRIMARY_OM_NAME}-db" export APPDB_VERSION="8.0.5-ent" 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"
Confirme o estado inicial.
Confirm that the primary Ops Manager resource and its internally managed Application Database are in the
Runningphase:kubectl get om "${PRIMARY_OM_NAME}" --context "${K8S_CTX}" -n "${MDB_NS}" \ -o jsonpath='{.status.opsManager.phase} / appdb={.status.applicationDatabase.phase}{"\n"}' Confirme que o recurso Ops Manager possui o banco de dados do aplicativo 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}.
Crie o recurso MongoDB para o banco de dados de aplicativo externo.
Dê ao recurso o mesmo nome do banco de dados do aplicativo StatefulSet existente.
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 security: authentication: enabled: true modes: ["SCRAM"] ignoreUnknownUsers: true EOF
Confirme que o recurso MongoDB aguarda a propriedade.
Until the Ops Manager resource releases the StatefulSet, the MongoDB resource stays in the Pending phase. This is expected and isn't an error.
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"}'
A mensagem de status relata que o recurso não pode apropriar-se do StatefulSet do banco de dados do aplicativo.
Adicione a referência externa do banco de dados de aplicativos ao recurso Ops Manager.
kubectl patch om "${PRIMARY_OM_NAME}" \ --context "${K8S_CTX}" -n "${MDB_NS}" \ --type merge \ -p "{\"spec\":{\"externalApplicationDatabaseRef\":{\"name\":\"${APPDB_NAME}\",\"kind\":\"MongoDB\"}}}"
You can remove spec.applicationDatabase in the same patch. Leaving it in place has no effect: once you set spec.externalApplicationDatabaseRef, the Kubernetes Operator stops managing an internal Application Database for this resource.
Aguarde o término da migração.
kubectl wait --for=jsonpath='{.status.phase}'=Running \ mdb/"${APPDB_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
Verifique a migração.
Confirme que o recurso MongoDB possui o Banco de Dados do Aplicativo 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}.Confirm that the Ops Manager resource reports its Application Database as
Disabled, which means that the Kubernetes Operator no longer manages an internal Application Database for it:kubectl get om "${PRIMARY_OM_NAME}" --context "${K8S_CTX}" -n "${MDB_NS}" \ -o jsonpath='{.status.applicationDatabase.phase}{"\n"}' Confirme que os pods do Ops Manager não foram reiniciados verificando a idade e as contagens de reinicialização:
kubectl get pods --context "${K8S_CTX}" -n "${MDB_NS}"
Problemas comuns de migração
O recurso MongoDB relata um erro de versão
If the MongoDB resource 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, and keep the Ops Manager version and the Application Database version on the same major version.
O recurso MongoDB permanece pendente após o patch
The Kubernetes Operator must detach the StatefulSet before the MongoDB resource can take ownership of it. Confirm that you applied spec.externalApplicationDatabaseRef to the primary Ops Manager resource, and that the value of spec.externalApplicationDatabaseRef.name is exactly <primary-om-name>-db.
O recurso MongoDB relata um erro de projeto
If the MongoDB resource stays in the Pending phase with a project or registration error, the management Ops Manager public API might not have been ready when you created the resource. Confirm that the management Ops Manager resource is in the Running phase and that its API answers requests, then reconcile the resource again.
Os pods do Ops Manager são reiniciados durante a migração
Se os pods do Ops Manager forem reiniciados, a string de conexão computada será alterada. Para um conjunto de réplicas que usa a porta padrão, a string de conexão é idêntica antes e depois da migração. O Kubernetes Operator não oferece suporte a portas não padrão para esta migração.
Próximos passos
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.
To reverse this migration, see Return an External Application Database to Ops Manager.