We recommend using an external Mongo service, such as Atlas. If you’d like to run Mongo in the same cluster as your other NxCloud services, then please continue following this guide.
> helm repo add mongodb https://mongodb.github.io/helm-charts
> helm install community-operator mongodb/community-operator
If you’d like to encrypt you Mongo volumes, apply the encrypted storage
class kubectl apply -f encrypted-storage-class.yml
# NO ENCRYPTION (if you skipped the above step)
> kubectl apply -f examples/mongodb.yml
# WITH ENCRYPTION (if you followed step 2 above)
> kubectl apply -f examples/encrypted-mongodb.yml
This will create a secret. You can get the value of the secret as follows:
> kubectl get secret cloud-mongodb-nrwl-api-admin-user -o go-template='### nnn'
You might need to wait a bit for the Pods to be created before this secret will be available.
The result should look like
this: mongodb+srv://admin-user:DB_PASSWORD@cloud-mongodb-svc.default.svc.cluster.local/nrwl-api?replicaSet=cloud-mongodb&ssl=false
.
Extract the connection string and remember it. You’ll need to use in your secrets.yml
file.
Next steps: continue from step 2. onwards.
If you can’t run Mongo in Kubernetes, you can also set it up manually using our approved Docker image.
nxprivatecloud/nx-cloud-mongo:latest
docker run -t -i -p 27017:27017 \
-e MONGO_INITDB_ROOT_USERNAME=some-admin-usernamne -e MONGO_INITDB_ROOT_PASSWORD=someAdminPassword123 \
-v $PWD/mongo-data:/data/db \
--rm --name nx-cloud-mongo nxprivatecloud/nx-cloud-mongo:latest \
--wiredTigerCacheSizeGB 2 --bind_ip_all \
--replSet rs0 \
--keyFile /mongo-security/keyfile.txt
MONGO_INITDB_ROOT_USERNAME
and MONGO_INITDB_ROOT_PASSWORD
- this will enable auth on our DB-v $PWD/mongo-data:/data/db
- this will create a persistent volume mapping to the host, so the DB doesn’t disappear when the Docker image gets recreated.--wiredTigerCacheSizeGB 2
- This sets the memory limit of the DB. Try increasing it if you are having a lot of activity.--replSet rs0 --keyFile /mongo-security/keyfile.txt
- this sets up a simple replica set. You can ignore this, it’s an implementation detail needed for NxCloud connections.This is a sample connection string you can use when connecting to your instance above (note the extra URL params at the end): mongodb://<your-server-ip-or-address>:27017/?authSource=admin&directConnection=true
As of version latest-11-05-2023T11-28-04
(and all new calver based versions that are similar to 2305.11.3
) and higher, we strongly recommend you update from Mongo 4.2 to Mongo 6 for
your NxCloud installation.
Mongo upgrades need to be done incrementally between major versions. In both scenarios below, we’ll upgrade from Mongo 4.2 to 4.4 then to 5.0 then to 6.0.
If at any point you run into any issues, or you’d like us to assist you with the upgrade, please send an email to cloud-support@nrwl.io
If you’re using Mongo Atlas, you can do a rolling upgrade by editing your cluster’s configuration:
and first selecting Mongo 4.4, then Mongo 5.0, finally Mongo 6.0 (notice how it doesn’t let us upgrade from 4.4 straight to 6):
If you’re using the Mongo Operator, you’ll need to edit your Mongo ReplicaSet and apply the version changes incrementally, as Mongo doesn’t allow a direct 4.2 to 6.0 upgrade.
During the upgrade, we’ll need to continually update our feature compatibility version also.
Mongo requires that this featureCompatibilityVersion
always trails the version we want to upgrade to. For example, if our pods are on Mongo 4.4 and we want to upgrade them to Mongo 5, our featureCompatibilityVersion needs to be first set to 4.4.
It’s important you follow the exact steps in order:
mongodump
. You can ssh into any one of your pods, as they should have the same data./mongo.yml
fileversion: '4.4.20'
featureCompatibilityVersion: '4.2'
mongo.yml
file should now contain these 2 lines:
version: '4.4.20'
featureCompatibilityVersion: '4.2'
kubectl apply -f mongo.yml
kubectl get pods
to monitor thisfeatureCompatibilityVersion: '4.4'
kubectl apply -f mongo.yml
version: '5.0.17'
kubectl get pods
output should show healthy pods, with 2/2
availability and the AGE
of the pods should now also be reset (similar to the screenshot we saw above)featureCompatibilityVersion: '5.0'
kubectl apply -f mongo.yml
. You don’t need to wait/watch for pod upgrades as this change will be applied very quickly.kubectl apply -f ...
the change in the previous step Change to version: '6.0.5'
and apply it.
kubectl get pods
featureCompatibilityVersion: '6.0'
and apply the change. This change will be very quick.If you are unsure if your pods have finished upgrading between Mongo versions (as it takes a while for the Mongo operator to slowly do a rolling upgrade of your replicas) and you’d like to check what Mongo version your pods are on, you can exec into a pod and:
mongo --version # you can do this for each pod part of your replica set
To check the featureCompatibilityVersion
, exec into the pod and:
mongo -u admin-user -p <password> --authenticationDatabase nrwl-api
use nrwl-api
db.adminCommand({getParameter: 1, featureCompatibilityVersion: 1})
Although not necessary, you can use the above commands to check each of your 3 replicas is on the correct Mongo version and featureCompatibilityVersion
between the upgrade steps above.