Charmed MongoDB K8s Tutorials > Deploy a sharded cluster > 6. Integrate with other applications
Integrate MongoDB with other applications
While mongos
exists inside our application config-server
, its only purpose is to perform database admin operations. We have used this process throughout the tutorial so far to simplify our environment while learning about MongoDB operations, but doing so is not suitable for a production deployment.
In order to access the cluster safely, we will use Juju integrations to connect to Charmed Mongos K8s - a charm that acts as a router to connect client applications to sharded clusters.
Integrations are the easiest way to create a user for MongoDB in Charmed MongoDB K8s. An integration automatically creates a username, password, and database for the desired user/application. In this section of the tutorial, we will learn how to correctly access our MongoDB cluster by integrating with Charmed MongoDB K8s. We will also see how user management works via integrations.
Deploy mongos-k8s
and data-integrator
charms
To create a client connection to a sharded cluster, you must use the Charmed Mongos K8s router. For this tutorial, we will use the data-integrator
charm to connect the mongos charm with MongoDB.
To deploy mongos-k8s
and data-integrator
, run:
juju deploy data-integrator --config database-name=test-database
juju deploy mongos-k8s
Watch juju status --watch 1s
until the data-integrator
status is blocked
and the mongos-k8s
status is unknown
.
Integrate with MongoDB
Now we will connect our client application, data-integrator
, to the cluster via our mongos-k8s
router:
juju integrate mongos-k8s data-integrator
juju integrate config-server mongos-k8s
The data-integrator
status will stay
Please relate the data-integator with the desired product
until mongos is integrated with the config-server.
This is because mongos acts as a proxy and data-integrator waits for the actual url to connect to the cluster.
Watch juju status --watch 1s --relations
until the integrations are ready.
Remove the user
Removing the integration automatically removes the user that was created with it, and stops the mongos
router.
To remove the relation, run:
juju remove-relation config-server mongos-k8s
Next step: 7.Enable security