|
| 1 | + |
| 2 | +# Migration Guide: MongoDB Community Operator (MCO) to MongoDB Kubernetes Operator (MCK) |
| 3 | + |
| 4 | +This guide walks you through the complete process of migrating from the MongoDB Community Operator (MCO) to the MongoDB Kubernetes Operator (MCK). It ensures CRDs are preserved, services remain uninterrupted, and reconciliation is correctly handed over. |
| 5 | +This guide ensures the CRDs are retained using Helm's keep annotation and transitions smoothly to MCK. We have a codified guide as well - [Link](https://github.com/mongodb/mongodb-kubernetes/blob/f0050b8942545701e8cb9e42d54d14f0cb58ee6a/mongodb-community-operator/test/e2e/replica_set_operator_upgrade/replica_set_operator_upgrade_test.go#L28). |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## 📋 Prerequisites |
| 10 | + |
| 11 | +- Kubernetes cluster access with admin permissions. |
| 12 | +- Helm installed and configured. |
| 13 | +- Upgrade your MCO Helm chart to at least version `0.13.0` before proceeding, as this version introduced the critical CRD keep annotations (`"helm.sh/resource-policy": keep`). |
| 14 | + |
| 15 | +--- |
| 16 | + |
| 17 | +## 🚀 Migration Steps |
| 18 | + |
| 19 | +### 1. Upgrade to the Latest MCO Chart |
| 20 | + |
| 21 | +```bash |
| 22 | +helm repo add mongodb https://mongodb.github.io/helm-charts |
| 23 | +helm repo update |
| 24 | +helm upgrade --install mongodb-community-operator mongodb/community-operator |
| 25 | +``` |
| 26 | + |
| 27 | +✅ Verify that Community CRD have the keep annotation: |
| 28 | + |
| 29 | +```bash |
| 30 | +kubectl get crds | grep mongodb |
| 31 | +kubectl get crd mongodbcommunity.mongodbcommunity.mongodb.com -o yaml | grep 'helm.sh/resource-policy' |
| 32 | +``` |
| 33 | + |
| 34 | +You should see: |
| 35 | +```yaml |
| 36 | +helm.sh/resource-policy: keep |
| 37 | +``` |
| 38 | +
|
| 39 | +--- |
| 40 | +
|
| 41 | +### 2. Environment Variables |
| 42 | +**Note:** If you're using Helm (as recommended in this guide), these environment variables will be automatically set through the `values.yaml` configuration described in step 3. Manual environment variable updates are only needed for non-Helm deployments. |
| 43 | + |
| 44 | +The MongoDB Kubernetes Operator (MCK) uses different environment variables than the MongoDB Community Operator (MCO): |
| 45 | + |
| 46 | +| MCO Variable | MCK Variable | |
| 47 | +|----------------------------|----------------------------------| |
| 48 | +| `MONGODB_REPO_URL` | `MDB_COMMUNITY_REPO_URL` | |
| 49 | +| `MDB_IMAGE_TYPE` | `MDB_COMMUNITY_IMAGE_TYPE` | |
| 50 | +| `MONGODB_IMAGE` | `MDB_COMMUNITY_IMAGE` | |
| 51 | +| `AGENT_IMAGE` | `MDB_COMMUNITY_AGENT_IMAGE` | |
| 52 | + |
| 53 | + |
| 54 | +--- |
| 55 | + |
| 56 | +### 3. Update community specific Helm Settings |
| 57 | + |
| 58 | +All of the above environment variables can be configured in the values.yaml file. |
| 59 | +They are all namespaced under `community`. |
| 60 | + |
| 61 | +--- |
| 62 | + |
| 63 | +### 4. Scale Down the MCO Operator Deployment |
| 64 | + |
| 65 | +To prevent a split-brain between the MCO and MCK operator we scale down the MCO deployment: |
| 66 | + |
| 67 | +```bash |
| 68 | +kubectl scale deployment mongodb-community-operator --replicas=0 |
| 69 | +``` |
| 70 | + |
| 71 | +--- |
| 72 | + |
| 73 | +### 5. Install the MCK Operator |
| 74 | + |
| 75 | +Deploy the new MCK Helm release with your updated values: |
| 76 | + |
| 77 | +```bash |
| 78 | +helm install mongodb-kubernetes-operator mongodb/enterprise-operator -f values.yaml |
| 79 | +``` |
| 80 | + |
| 81 | +⚠️ Warning: Ensure the MCK chart is installed with a different release name than the prior community operator chart. By default, the new MCK chart uses a different `operator.name`, which differs from the community operator. |
| 82 | +If you've modified the community operator's name/release name, ensure the MCK's `operator.name` value is different |
| 83 | +to avoid RBAC conflicts, since service accounts, roles, and other resources are based on this name. |
| 84 | + |
| 85 | +--- |
| 86 | + |
| 87 | +### 6. Let MCK Reconcile the Existing Resources |
| 88 | + |
| 89 | +After installation: |
| 90 | + |
| 91 | +- MCK will take control of existing MongoDB CRs. |
| 92 | +- It will apply updated container images, RBAC settings, and other resources. |
| 93 | +- A rolling restart will occur as service account names are updated among other things (e.g. to `mongodb-kubernetes-appdb`). |
| 94 | + |
| 95 | +--- |
| 96 | + |
| 97 | +### 7. Wait for All Resources to Become Healthy |
| 98 | + |
| 99 | +Monitor the cluster: |
| 100 | + |
| 101 | +```bash |
| 102 | +kubectl get pods |
| 103 | +kubectl get mdbc -A |
| 104 | +``` |
| 105 | + |
| 106 | +Wait until: |
| 107 | + |
| 108 | +- All pods are running |
| 109 | +- All MongoDB resources are reconciled |
| 110 | +- No errors are shown in the MCK operator logs |
| 111 | + |
| 112 | +--- |
| 113 | + |
| 114 | +### 8. Uninstall the MCO Chart |
| 115 | + |
| 116 | +Once MCK has taken over, remove the MCO chart: |
| 117 | + |
| 118 | +```bash |
| 119 | +helm uninstall mongodb-community-operator |
| 120 | +``` |
| 121 | + |
| 122 | +- Helm will retain the CRDs due to the `keep` annotation |
| 123 | +- Old RBAC resources will be removed, but are no longer needed since we've installed new ones to use |
| 124 | + |
| 125 | +--- |
| 126 | + |
| 127 | +## ✅ Final Verification |
| 128 | + |
| 129 | +1. Check CRDs still exist after uninstalling the MCO chart: |
| 130 | + |
| 131 | +```bash |
| 132 | +kubectl get crds | grep mongodb |
| 133 | +``` |
| 134 | + |
| 135 | +2. Ensure MCK logs show successful reconciliation. |
| 136 | + |
| 137 | +--- |
| 138 | + |
| 139 | +## 💬 Support |
| 140 | + |
| 141 | +For questions or issues during the migration, refer to the [official MCK repository](https://github.com/mongodb/mongodb-kubernetes) or contact your support representative. |
0 commit comments