Skip to content

canonical/mongos-k8s-operator

Repository files navigation

Charmed Mongos K8s operator

Charmhub Release to 6/edge Tests

Overview

The Charmed Mongos K8s operator deploys and operates mongos instances on Kubernetes.

mongos is a router for connecting client applications to a sharded MongoDB K8s clusters. It is the only way to access a sharded MongoDB cluster from the client perspective.

To deploy a sharded MongoDB cluster, see our charmed solution for MongoDB K8s.

For information about how to deploy, integrate, and manage this charm, see the Official Charmed Mongos documentation.

Get started

The following steps will guide you through briefly creating a client connection to a sharded MongoDB cluster via mongos-k8s.

You'll need a Juju environment and a MongoDB K8s application deployed as a sharded cluster. For guidance about setting up your environment, see the Charmed MongoDB K8s tutorial.

Deploy

To deploy a MongoDB K8s sharded cluster with one shard, run:

juju deploy mongodb-k8s --config role="config-server" config-server --trust
juju deploy mongodb-k8s --config role="shard" shard0 --trust

The --trust flag is necessary to grant the application access to the Kubernetes cluster.

To deploy mongos-k8s and data-integrator, run:

juju deploy mongos-k8s --trust
juju deploy data-integrator --config database-name=<name>

Integrate

When the status of the mongos-k8s application becomes idle, integrate mongos-k8s with data-integrator and with the mongodb application running as config-server:

juju integrate mongos-k8s data-integrator
juju integrate config-server mongos-k8s

Access the database

In order to access the integrated database, you will need the mongos URI. To retrieve this, run the following command:

juju run data-integrator/leader get-credentials

You will find the URI under the field uris in the output.

Enable TLS

If the sharded MongoDB cluster has TLS enabled, mongos-k8s must also enable TLS. Enable it by integrating mongos-k8s with a TLS application:

juju integrate mongos-k8s <tls-application>

For more information about TLS in sharded clusters, see the Charmed MongoDB documentation for enabling security in sharded clusters

External connections

If you would like to connect the sharded MongoDB K8s cluster outside of Juju, this is possible with the configuration expose-external in the mongos-k8s charm.

Simply configure the charm to use nodeport:

 juju config mongos-k8s expose-external=nodeport

This will make the mongos router accessible outside of Juju and will provide you access to the cluster. You will now see that all of your client URIs have been updated.

For example run:

juju run data-integrator get-credentials

You will see that the URI has changed.

To reconfigure the charm to have internal access only, run:

 juju config mongos-k8s expose-external=none

Remove mongos

To remove a mongos connection to the sharded cluster, run:

juju remove-relation config-server mongos

Whenmongos is removed from the sharded cluster, the client is removed as well.

Learn more

Project and community

Charmed Mongos K8s is an open source project that warmly welcomes community contributions, suggestions, fixes, and constructive feedback.