Service discovery is one of the most important features of a functioning clustered environment. When applications are being launched on random ports, on a potentially large group of hosts, your applications need to know how to find the services they need to function.
In order for this to occur, the following typically has to happen: - Your application has to register itself with the discovery system - Your application has to deregister itself when it shuts down - Something else has to perform those tasks on behalf of your application
Most of these options are a pain to implement or require changes in your code. With our solution you don't need to change anything if you're already using environment variables for setting application configuration.
The Containership discovery system is an integration of Quarry, our internal DNS system, a special HaProxy based container (running with a 1 per_host Constraint), Automatically Added Environment Variables, and the application specific _discovery_port_.
Every Application you launch on Containership has a few important settings that allow for zero hassle discovery.
"id": "my-app", "discovery_port": 10542
The id of the application is used to reference it by name and the _discovery_port_ is a static port assigned to the application globally across the cluster.
Any request made to a follower host on that application's _discovery_port_ will access the corresponding containers for that application. This includes containers that could be (and in many cases are) running on different follower hosts.
# Tying it together with Environment Variables Integrating service discovery into your application is easy, and does not require any libraries or code changes.
Let's imagine that somewhere in your 'my-app' code, you need to configure your application to access an API that you already have running called 'my-api'. All you need to do is use an environment variable in your code, that we will reference later when launching 'my-app'. For example:
var apiName = process.ENV.API_NAME
# Utilizing When you are ready to launch the 'my-app' application to test it, all you need to do is set the API_NAME environment variable to the name of the application that you want to access, followed by $cluster-id.containership . In this case it's the 'my-api' application.
"env_vars" : { "API_NAME": "my-api.$cluster-id.containership"}
Traffic will be automatically load balanced across all of the available 'my-api' containers.
# Pro Tip When using the Cloud Ui or Navigator it's even easier as we create environment variables for each application that allow you to reference the discovery_port and address of any application you have running. See Application Linking.