Starting in Kubernetes Operator 1.15, standalone deployments are deprecated and lose support in the next major version. Migrate your standalone deployments to one-member replica sets. A one-member replica set provides the same single-node topology as a standalone instance and supports adding members later without migrating again.
About this Task
This migration isn't an in-place upgrade. You deploy a new one-member replica set, copy your data with mongodump and mongorestore, and then direct your applications to the replica set.
A Ops Manager project holds one deployment, so the replica set requires a new project. You can't reuse the project that the standalone deployment uses.
mongodumpandmongorestoredon't copy database users. After the restore, recreate your users asMongoDBUserresources.The standalone deployment stays intact until you delete it. If the migration fails, you can direct your applications back to the standalone deployment.
Before You Begin
Deploy a standalone resource that the Kubernetes Operator manages. To learn more, see Deploy a Standalone MongoDB Instance.
Configure
kubectlto access the Kubernetes cluster that hosts the standalone deployment.Note the value of
spec.versionin the standalone resource. The one-member replica set must run the same MongoDB version.
Procedure
Create a ConfigMap for a new project.
A Ops Manager project holds one deployment, so you can't reuse the project that the standalone deployment uses. Copy the ConfigMap that the standalone deployment references, keep the baseUrl and orgId values, and set a new, unique projectName. Apply the ConfigMap to the same Kubernetes namespace as the standalone deployment.
To learn more, see Create One Project Per MongoDB Deployment Using a ConfigMap.
Deploy a one-member replica set.
Create a MongoDB resource with spec.type set to ReplicaSet and spec.members set to 1. Set spec.version to the same MongoDB version that the standalone deployment runs, and reference the ConfigMap that you created in the preceding step. You can reuse the credentials secret that the standalone deployment uses. Copy any additional spec settings from the standalone resource.
apiVersion: mongodb.com/v1kind: MongoDBmetadata: name: <my-replica-set> namespace: <my-namespace>spec: members: 1 # Must match the MongoDB version of the standalone deployment version: "<mongodb-version>" opsManager: configMapRef: # Must match metadata.name in the new project ConfigMap file name: <configMap.metadata.name> # Can match the credentials Secret that the standalone deployment uses credentials: <mycredentials> type: ReplicaSet persistent: trueApply the resource:
kubectl apply -f <replica-set-yaml> --namespace <my-namespace>To check the status of your MongoDB resource, use the following command:
kubectl get mdb <resource-name> -o yaml -wWith the -w (watch) flag set, when the configuration changes, the output refreshes immediately until the status phase achieves the Running state. To learn more about resource deployment statuses, see Troubleshoot the Kubernetes Operator.
Deploy a tools pod.
The container images that run the database pods don't include the MongoDB Database Tools. To run mongodump and mongorestore, deploy a dedicated tools pod based on the mongodb-enterprise-server image. Set the image tag to the same MongoDB version that the standalone deployment runs.
apiVersion: v1kind: Podmetadata: name: mongodb-tools namespace: <my-namespace>spec: containers: - name: mongodb-tools # Use the standalone's MongoDB version without the -ent # suffix, for example 8.0.4 image: quay.io/mongodb/mongodb-enterprise-server:<mongodb-version>-ubi9 command: ["sleep", "infinity"]Apply the pod:
kubectl apply -f <tools-pod-yaml> --namespace <my-namespace>Record document counts and a database hash.
Record the document count of each collection and the dbHash of each database on the standalone deployment, except the admin, config, and local databases. The restore excludes the admin and config databases, and replication writes to the local database, so these values never match. After the restore, you repeat these measurements against the replica set to verify the migration.
Dump the standalone data.
Run mongodump from the tools pod against the standalone deployment's service:
kubectl exec mongodb-tools --namespace <my-namespace> -- \ mongodump \ --host "<my-standalone>-svc.<my-namespace>.svc.cluster.local:27017" \ --out /tmp/dumpIf the standalone deployment requires authentication, connect as a user that has the backup and readAnyDatabase roles. If the deployment requires TLS, add the corresponding mongodump connection options. To learn more, see mongodump.
Restore the data to the replica set.
Run mongorestore from the tools pod against the replica set's service:
kubectl exec mongodb-tools --namespace <my-namespace> -- \ mongorestore \ --host "<my-replica-set>-svc.<my-namespace>.svc.cluster.local:27017" \ --nsExclude="admin.*" \ --nsExclude="config.*" \ /tmp/dumpThe --nsExclude options exclude the admin and config databases from the restore. A full mongodump output includes admin.system.users and admin.system.version. Restoring them would write database users and the authentication schema into the replica set outside of the automation configuration, so the project's user list in Ops Manager would no longer match the database.
If the replica set requires authentication, the replica set has no users yet because you recreate your database users in a later step. Create a temporary MongoDBUser resource in the new project with the restore, readWriteAnyDatabase, and dbAdminAnyDatabase roles, and connect as that user. To learn more about creating users, see Manage Database Users.
If the replica set requires TLS, add the corresponding mongorestore connection options. To learn more, see mongorestore.
Recreate the database users.
The dump doesn't carry database users. Recreate each user as a MongoDBUser resource in the new project. If you created a temporary user for the restore, delete it after you recreate your users. To learn more, see Manage Database Users and MongoDB User Resource Specification.
Delete the standalone deployment.
After you verify the migration, delete the standalone MongoDB resource. The Kubernetes Operator doesn't delete the persistent volume claim that the standalone deployment used, so delete the claim manually. To learn more, see Remove a MongoDB resource.
Rollback
The standalone deployment stays intact until you delete it. To roll back the migration, direct your applications back to the standalone deployment. The standalone deployment doesn't contain writes that the replica set received after the cutover.