---
title: Charmhub | Deploy mongos-k8s using Charmhub - The Open Operator Collection
description: Deploy the latest version of mongos-k8s as a Kubernetes Operator on any
  cloud. A mongos k8s operator charm
url: https://charmhub.io/mongos-k8s
---

# mongos-k8s

[Canonical](https://charmhub.io/publisher/data-platform "View all packages from Canonical")

* [Canonical](https://charmhub.io/publisher/data-platform "View all packages from Canonical")

Platform:

6/stable 75

```
juju deploy mongos-k8s --channel 6/stable
```

[Learn to deploy on juju >](https://juju.is/docs/juju/manage-applications)

---

#### Relevant links

* [Homepage](https://github.com/canonical/mongos-k8s-operator)

---

#### Contacts

* [Submit a bug](https://github.com/canonical/mongos-k8s-operator/issues)

---

Share your thoughts on this charm with the community on discourse.

[Join the discussion](https://discourse.charmhub.io/)

# Charmed Mongos K8s documentation

The Charmed Mongos K8s operator deploys and operates [`mongos`](https://www.mongodb.com/docs/v6.0/reference/program/mongos/) instances on Kubernetes.

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

To deploy a sharded MongoDB cluster, please see our [Charmed MongoDB K8s operator](https://charmhub.io/mongodb-k8s).

## [Summary](https://charmhub.io/mongos-k8s#p-34219-summary)

* [Get started](https://charmhub.io/mongos-k8s#get-started)
  + [Deploy and integrate mongos](https://charmhub.io/mongos-k8s#deploy-and-integrate)
  + [Access the database](https://charmhub.io/mongos-k8s#access-the-database)
  + [Enable TLS encryption](https://charmhub.io/mongos-k8s#enable-tls-encryption)
  + [External connections](https://charmhub.io/mongos-k8s#external-connections)
  + [Remove the connection](https://charmhub.io/mongos-k8s#remove-the-connection)
* [Learn more](https://charmhub.io/mongos-k8s#learn-more)
* [Project and community](https://charmhub.io/mongos-k8s#project-and-community)

---

## [Get started](https://charmhub.io/mongos-k8s#p-34219-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 more guidance, see the [Charmed MongoDB K8s deployment guide](https://charmhub.io/mongodb-k8s/docs/h-deploy).

### [Deploy and integrate](https://charmhub.io/mongos-k8s#p-34219-deploy-and-integrate)

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

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

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

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

### [Access the database](https://charmhub.io/mongos-k8s#p-34219-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.

Then SSH into the unit and access the `mongo` shell:

```
juju ssh --container mongos mongos-k8s/0
mongosh <URI>
```

### [Enable TLS encryption](https://charmhub.io/mongos-k8s#p-34219-enable-tls-encryption)

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>
```

`<tls-application>` must be the same TLS application that the sharded MongoDB cluster is integrated to.

For more information about TLS in sharded clusters, see the [Charmed MongoDB K8s documentation](https://charmhub.io/mongodb-k8s/docs/h-enable-tls)

### [External connections](https://charmhub.io/mongos-k8s#p-34219-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 the connection](https://charmhub.io/mongos-k8s#p-34219-remove-the-connection)

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

```
juju remove-relation config-server mongos-k8s
```

When`mongos-k8s` is removed from the sharded cluster, the client is removed as well.

## [Learn more](https://charmhub.io/mongos-k8s#p-34219-learn-more)

* Learn more about operating MongoDB sharded clusters and replica sets in the [Charmed MongoDB K8s documentation](https://charmhub.io/mongodb-k8s)
* Check the charm’s [GitHub repository](https://github.com/canonical/mongos-k8s-operator)
* Learn more about the `mongos` router in the upstream [`mongos` documentation](https://www.mongodb.com/docs/v6.0/reference/program/mongos/)

## [Project and community](https://charmhub.io/mongos-k8s#p-34219-project-and-community)

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

* Check our [Code of Conduct](https://ubuntu.com/community/ethos/code-of-conduct)
* Raise software issues or feature requests on [GitHub](https://github.com/canonical/mongos-k8s-operator/issues)
* Report security issues through [LaunchPad](https://wiki.ubuntu.com/DebuggingSecurity#How%20to%20File).
* Meet the community and chat with us on [Matrix](https://matrix.to/#/#charmhub-data-platform:ubuntu.com)
* [Contribute](https://github.com/canonical/mongodb-k8s-operator/blob/main/CONTRIBUTING.md) to the code

## [License](https://charmhub.io/mongos-k8s#p-34219-license)

The Charmed Mongos Operator is free software, distributed under the [Apache Software License, version 2.0](https://github.com/canonical/mongos-k8s-operator/blob/main/LICENSE). It installs, operates, and depends on [MongoDB Community Version](https://github.com/mongodb/mongo), which is licensed under the Server Side Public License (SSPL)

MongoDB is a trademark or registered trademark of MongoDB, Inc. Other trademarks are property of their respective owners.

---

[Help improve this document in the forum](https://discourse.charmhub.io/t/charmed-mongos-k8s-documentation/15817) ([guidelines](https://discourse.charmhub.io/t/how-to-write-docs-our-documentation-guidelines-for-contributors/1245)). Last updated 11 months ago.
