Skip to content

Instantly share code, notes, and snippets.

@mildred
Created January 5, 2018 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mildred/9464dedfd6b0bb069dce6b75eebb18dc to your computer and use it in GitHub Desktop.
Save mildred/9464dedfd6b0bb069dce6b75eebb18dc to your computer and use it in GitHub Desktop.
Namespaces in consul / nomad

A namespace is a collection of nomad jobs in the same directory. Sub-directories are sub-namespaces. When instanciated, a namespace is allocated an identifier (8 character unique ID). Before being inserted in nomad, the jobs are modified to include this namespace identifier:

  • the nomad job name is prefixed by "NAMESPACE-" (the namespace identifier)
  • the consul service definitions are prefixed by "NAMESPACE-" (the namespace identifier)
  • the services have an additional environment variable: CONSUL_NAMESPACE_ID

sub-namespaces are also inserted in the system when their parent namespace is inserted. Each sub-namespace is given an identifier the same way. The parent namespace is instanciated with:

  • an environment variable CONSUL_NAMESPACE_ID_FOR_subnsname containing the sub namespace identifier

We can imageine a complex system using namespace hierarchy like this:

  • main/ application namespace containing:
    • web-service.nomad (instanciated as "00000001-web-service")
    • helper.nomad (instanciated as "00000001-helper")
    • smtp/ server sub namespace:
      • exim.nomad (instanciated as "00000002-exim")
      • dovecot.nomad (instanciated as "0000002-dovecot")

web-service knows how to contact exim because it can find it using the consul name "${CONSUL_NAMESPACE_ID_FOR_SMTP}-exim.service.consul"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment