Connecting Clients

Connecting clients with service discovery

Connecting Clients

One of the benefits of running containerized services is that they can be placed anywhere in the cluster. Because they can be deployed anywhere on the cluster, clients need a way to find the service. This is where service discovery comes in.

Discovering Endpoints

Once the service is running, you may view information about its endpoints via either of the following methods:

  • CLI:
    • List endpoint types: dcos percona-server-mongodb endpoints
    • View endpoints for an endpoint type: dcos percona-server-mongodb endpoints <endpoint>
  • API:
    • List endpoint types: <dcos-url>/service/percona-server-mongodb/v1/endpoints
    • View endpoints for an endpoint type: <dcos-url>/service/percona-server-mongodb/v1/endpoints/<endpoint>

Returned endpoints will include the following:

  • hostnames for each instance that will follow them if they are moved within the DC/OS cluster.
  • A HA-enabled VIP hostname for accessing any of the instances (optional).
  • A direct IP address for accessing the service if hostnames are not resolvable.
  • If your service is on a virtual network such as the dcos overlay network, then the IP will be from the subnet allocated to the host that the task is running on. It will not be the host IP. To resolve the host IP use Mesos DNS (<task>.<service>.mesos).

In general, the endpoints will only work from within the same DC/OS cluster. From outside the cluster you can either use direct IPs or set up a proxy service that acts as a front end to your percona-server-mongodb instance. For development and testing purposes, you can use DC/OS Tunnel to access services from outside the cluster, but this option is not suitable for production use.

Connecting Clients to Endpoints

  1. Gather the DNS names for the mongo-port endpoint.
$ dcos percona-server-mongodb endpoints mongo-port
      "address": [
      "dns": [
  1. Connect to MongoDB using the mongo shell tool, using the dns hostname+port list from Step 1. Note that a username and password is provided in the connect string, as well as the replica set name:
$ mongo mongodb://,,
> db.serverStatus();

Or for applications, most MongoDB drivers will accept mongodb:// connection-string used in the example above to connect to MongoDB.