Running Nomatron Server as a Nomad Job

Nomatron is in early access. Some advanced workflows may not be covered in the public docs.

Running Nomatron as a Nomad job lets you manage the control plane in the same scheduler as the workloads it eventually governs.

For many teams, this is the most natural production deployment model because Nomad already provides:

  • job scheduling;
  • restart and update orchestration;
  • placement controls;
  • templating;
  • service registration on newer versions; and
  • a clean path to multi-node deployments.

This page covers the operational shape that works best in practice, including what to do on older Nomad versions that do not yet have built-in service registration or Nomad Variables.

One important runtime detail: in normal mode, Nomatron always starts Serf. That means your Nomad-rendered config still needs a serf stanza even for a single-server deployment. The single-node case is simpler because it does not need peer joins, but it does still need a valid local Serf configuration.

Best-Practice Shape

For most production deployments, the recommended shape is:

  1. use a dedicated Nomad namespace for Nomatron;
  2. keep PostgreSQL outside the Nomatron job;
  3. run nomatron database init separately before starting the service job;
  4. use Nomad template stanzas to render the Nomatron config file;
  5. start with a single Nomatron server if you are evaluating or bootstrapping;
  6. move to three Nomatron servers for higher availability; and
  7. make sure multi-server allocations land on different Nomad clients.

That gives you the cleanest separation between:

  • Nomatron control plane state;
  • scheduler placement and lifecycle;
  • shared database state; and
  • Nomatron cluster membership.

Before You Start

Have these pieces ready before submitting the Nomad job:

  • a Nomad cluster;
  • the published Nomatron server image;
  • an external PostgreSQL instance;
  • a Nomatron licence key, and a cluster key you generate yourself (connected licence mode, the default);
  • a NOMATRON_ENCRYPTION_KEY value (32 bytes, base64; generate with openssl rand -base64 32), the same one used for nomatron database init;
  • a completed nomatron database init;
  • a hostname or load balancer plan for the Nomatron UI and API; and
  • a decision about whether you are running a single server or multiple servers.

Do not use nomatron server --dev in Nomad. Dev mode is for local workstation use and shells out to the Docker CLI to create its own temporary PostgreSQL dependency.

Why A Dedicated Namespace Is A Good Idea

A dedicated namespace is a strong default for Nomatron because it:

  • separates Nomatron jobs from tenant workloads;
  • simplifies ACL policy boundaries;
  • makes service discovery less noisy;
  • reduces the risk of accidental job name collisions; and
  • makes operational ownership clearer.

A typical pattern is:

hcl
namespace = "nomatron"

If your cluster does not use namespaces, keep the Nomatron job names and service names unambiguous and avoid deploying it into a crowded general-purpose operations namespace unless you have a strong reason to do so.

Older Nomad Versus Newer Nomad

The page uses two compatibility tracks:

Older Nomad

On older Nomad versions, you may not have:

  • built-in service registration; or
  • Nomad Variables.

In that case:

  • omit or simplify the service stanza;
  • use static ports, external DNS, Consul, or a load balancer you manage yourself;
  • pass secrets and runtime values through Nomad job variables, environment variables, Vault integration, or another secret mechanism available in your environment; and
  • keep peer retry_join addresses explicit in your config because the job cannot rely on Nomad-native service discovery to build the cluster member list for you.

Newer Nomad

On newer Nomad versions, take advantage of:

  • built-in service registration with provider = "nomad";
  • Nomad health checks;
  • Nomad Variables for sensitive runtime values; and
  • richer template rendering workflows.

This is especially valuable once you run multiple Nomatron servers, because it gives you a cleaner way to expose the HTTP endpoint and manage runtime configuration without hardcoding everything into the job file.

For newer Nomad clusters, the best pattern is usually:

  • register the HTTP endpoint as a Nomad service;
  • register the Serf endpoint as a separate Nomad service;
  • use a Nomad template stanza to render the Serf retry_join list from service discovery; and
  • avoid hardcoding peer IP addresses entirely.

What Still Lives Outside The Job

Even when Nomatron runs in Nomad, these dependencies still need an external operational home:

  • PostgreSQL;
  • TLS termination, unless you intentionally terminate TLS inside Nomatron;
  • persistent backup and restore procedures; and
  • any external DNS or load balancer you use for the public API and UI.

The Nomad job manages process lifecycle, placement, and configuration rendering. It does not remove the need for durable external state.

Keep the Nomatron server on its default internal ports:

  • 4649 for HTTP and the web UI;
  • 4650 for the agent gRPC server; and
  • 7946 for Serf (TCP and UDP).

That maps cleanly to the current server behavior and avoids confusion in task networking.

Single-Server Baseline Job

This is a good starting point for:

  • evaluation environments;
  • internal staging;
  • first production rollout in a small environment; or
  • older Nomad clusters where you want the simplest possible deployment model.
hcl
job "nomatron" {
  datacenters = ["dc1"]
  type        = "service"
  namespace   = "nomatron"

  update {
    max_parallel      = 1
    min_healthy_time  = "10s"
    healthy_deadline  = "5m"
    progress_deadline = "10m"
    auto_revert       = true
  }

  group "server" {
    count = 1

    network {
      mode = "bridge"

      port "http" {
        to = 4649
      }

      port "grpc" {
        to = 4650
      }

      port "serf" {
        to = 7946
      }
    }

    restart {
      attempts = 10
      interval = "30m"
      delay    = "15s"
      mode     = "delay"
    }

    task "nomatron" {
      driver = "docker"

      config {
        image = "ghcr.io/nomatronio/nomatron-releases/nomatron:v0.1.7"
        args  = ["server", "--config", "${NOMAD_TASK_DIR}/nomatron.hcl"]
        ports = ["http", "grpc", "serf"]
      }

      template {
        destination = "local/nomatron.hcl"
        data = <<EOF
server {
  port     = 4649
  api_addr = "https://${var.api_hostname}"
}

serf {
  node_name = "${node.unique.name}"
  bind_addr = "0.0.0.0"
  port      = 7946
}
EOF
      }

      template {
        destination = "secrets/nomatron.env"
        env         = true
        data        = <<EOF
{{- with nomadVar "nomad/jobs/nomatron/server/nomatron" }}
NOMATRON_DB_URL={{ .db_url }}
NOMATRON_LICENSE_KEY={{ .license_key }}
NOMATRON_CLUSTER_KEY={{ .cluster_key }}
NOMATRON_ENCRYPTION_KEY={{ .encryption_key }}
{{- end }}
EOF
      }

      resources {
        cpu    = 1000
        memory = 1024
      }
    }
  }
}

variable "api_hostname" {
  type        = string
  description = "Primary hostname that fronts Nomatron, e.g. nomatron.example.com."
}

This version is intentionally conservative:

  • one server;
  • no Serf retry_join peers;
  • secrets (database URL, licence key, cluster key, encryption key) read from a Nomad Variable into environment variables, so they never appear in the job file or the rendered nomatron.hcl;
  • a minimal Serf stanza because normal-mode Nomatron always starts Serf;
  • no built-in service registration required; and
  • config rendered from a Nomad template.

Why Templates Are The Right Default

Nomad template stanzas are a strong fit for Nomatron because they let you:

  • render a real nomatron.hcl file instead of cramming everything into environment variables;
  • combine job variables, secrets, and deployment-specific values in one place;
  • keep the Nomatron runtime shape close to the documented config reference; and
  • clearly separate what changes per environment from what stays static.

This is usually easier to maintain than a long list of env {} entries once the deployment becomes more serious.

Service Registration On Newer Nomad

If your Nomad version supports built-in service registration, add a service block and health check:

hcl
service {
  name     = "nomatron-server"
  port     = "http"
  provider = "nomad"

  check {
    name     = "nomatron-health"
    type     = "http"
    path     = "/api/v1/health"
    interval = "15s"
    timeout  = "5s"
  }
}

That gives you:

  • a registered service for HTTP traffic;
  • built-in health visibility in Nomad; and
  • a cleaner path to fronting the service with other Nomad-aware components.

If your Nomad version does not support this, omit the service stanza and publish the HTTP endpoint through your own DNS, Consul, or load balancer workflow.

Multi-Server Nomatron On Nomad

When you want a more durable deployment, move to three Nomatron servers.

For multi-server deployments:

  • run at least three Nomatron servers;
  • place them on different Nomad clients;
  • use a shared PostgreSQL database;
  • configure Serf explicitly; and
  • put the HTTP service behind a load balancer or ingress layer.

The important placement rule is simple: do not let all three allocations land on the same client.

Example Multi-Server Job With Nomad Service Discovery

hcl
job "nomatron" {
  datacenters = ["dc1"]
  type        = "service"
  namespace   = "nomatron"

  update {
    max_parallel      = 1
    min_healthy_time  = "15s"
    healthy_deadline  = "10m"
    progress_deadline = "15m"
    auto_revert       = true
    canary            = 1
  }

  group "server" {
    count = 3

    constraint {
      operator = "distinct_hosts"
      value    = "true"
    }

    network {
      mode = "host"

      port "http" {
        static = 4649
        to     = 4649
      }

      port "grpc" {
        static = 4650
        to     = 4650
      }

      port "serf" {
        static = 7946
        to     = 7946
      }
    }

    service {
      name     = "nomatron-server"
      port     = "http"
      provider = "nomad"

      check {
        name     = "nomatron-health"
        type     = "http"
        path     = "/api/v1/health"
        interval = "15s"
        timeout  = "5s"
      }
    }

    service {
      name     = "nomatron-serf"
      port     = "serf"
      provider = "nomad"
    }

    task "nomatron" {
      driver = "docker"

      config {
        image = "ghcr.io/nomatronio/nomatron-releases/nomatron:v0.1.7"
        args  = ["server", "--config", "${NOMAD_TASK_DIR}/nomatron.hcl"]
        network_mode = "host"
      }

      template {
        destination = "local/nomatron.hcl"
        data = <<EOF
server {
  port     = 4649
  api_addr = "https://${var.api_hostname}"
}

serf {
  node_name      = "${node.unique.name}"
  bind_addr      = "0.0.0.0"
  advertise_addr = "${attr.unique.network.ip-address}"
  port           = 7946
  retry_join     = [{{- range nomadService "nomatron-serf" -}}{{- if ne .Address (env "attr.unique.network.ip-address") -}}"{{ .Address }}:{{ .Port }}",{{- end -}}{{- end -}}]
}
EOF
      }

      template {
        destination = "secrets/nomatron.env"
        env         = true
        data        = <<EOF
{{- with nomadVar "nomad/jobs/nomatron/server/nomatron" }}
NOMATRON_DB_URL={{ .db_url }}
NOMATRON_LICENSE_KEY={{ .license_key }}
NOMATRON_CLUSTER_KEY={{ .cluster_key }}
NOMATRON_ENCRYPTION_KEY={{ .encryption_key }}
NOMATRON_SERF_ENCRYPT_KEY={{ .serf_encrypt_key }}
{{- end }}
EOF
      }

      resources {
        cpu    = 1000
        memory = 1024
      }
    }
  }
}

variable "api_hostname" {
  type        = string
  description = "Primary hostname that fronts Nomatron."
}

This layout makes a few deliberate choices:

  • count = 3 for a more resilient control plane;
  • distinct_hosts so all servers do not land on the same Nomad client;
  • mode = "host" so Serf advertising is simpler and more predictable;
  • Nomad service discovery for the Serf retry_join list, so peer IPs do not need to be known in advance; and
  • one public API hostname fronting all Nomatron servers through a load balancer.

For clustered Nomatron, this is a better operational default than a single shared bridge network with opaque dynamic Serf addressing.

Why This Is Better Than Hardcoding Peer IPs

Using Nomad service registration for the Serf member list is a better default on newer Nomad because it:

  • removes the need to know peer IP addresses ahead of time;
  • adapts more cleanly to rescheduling;
  • keeps the cluster member list aligned with live Nomad allocations; and
  • avoids manual edits every time a Nomatron server moves.

That makes the job more robust than maintaining a static retry_join list by hand.

serf.join was removed. Always use retry_join. For cloud auto-join outside Nomad service discovery, see Server HA Cloud Auto-Join .

Fallback For Older Nomad

If your Nomad version cannot render the retry_join list from service discovery, fall back to an explicit peer list:

hcl
serf {
  node_name      = "${node.unique.name}"
  bind_addr      = "0.0.0.0"
  advertise_addr = "${attr.unique.network.ip-address}"
  port           = 7946
  retry_join     = ["192.0.2.21:7946", "192.0.2.22:7946", "192.0.2.23:7946"]
}

That is still a valid approach. It is just less elegant than letting newer Nomad service discovery populate the cluster member list for you.

Why Host Networking Is Often Better For Multi-Server Setups

You can run clustered Nomatron under bridge networking, but host networking is often easier because:

  • Serf advertise addresses are clearer;
  • peer join addresses are less surprising;
  • static ports are easier to reason about; and
  • troubleshooting is simpler when the node IP and advertised Serf address are the same thing.

For a single-server deployment, bridge networking is usually fine.

For a multi-server deployment, host networking is often the less painful choice.

Using Nomad Variables On Newer Clusters

The example jobs above read sensitive values from the Nomad Variable nomad/jobs/nomatron/server/nomatron, which the nomatron task can read automatically. Store these items in it:

  • db_url;
  • license_key;
  • cluster_key;
  • encryption_key; and
  • serf_encrypt_key (multi-server only; generate with nomatron keygen).

Create it from a spec file kept out of source control, for example nomad var put -namespace nomatron @nomatron-secrets.json.

Generate the cluster key yourself, for example with openssl rand -base64 32. Keep the cluster key and encryption key for the life of the database. Nomatron does not store or issue cluster keys, so back it up in your secrets manager; it cannot be recovered if lost.

The exact rendering details depend on how your Nomad environment exposes variables into templates, but the operational goal is straightforward:

  • keep sensitive values out of the main job file;
  • render them into nomatron.hcl at allocation time; and
  • let Nomad manage the secured source of truth.

If your Nomad version does not support Nomad Variables, use one of:

  • Nomad job variables supplied at submit time;
  • Vault integration;
  • environment variables injected by your platform; or
  • another secret delivery path your cluster already trusts.

Do Not Re-Run Database Init In Every Allocation

Treat nomatron database init as a bootstrap step, not as part of the long-running server task.

Best practice is:

  1. initialize the database once;
  2. verify the root bootstrap state;
  3. then start the service job.

Do not wrap database init into every server restart, and do not rely on server allocation churn as a credential-management mechanism.

Suggested Operational Pattern

For a mature Nomad deployment, the best-practice pattern is usually:

  1. dedicated namespace;
  2. external PostgreSQL;
  3. Nomad template stanza rendering nomatron.hcl;
  4. built-in Nomad service registration and health checks when available;
  5. Nomad Variables or Vault for sensitive values;
  6. three Nomatron servers on different clients; and
  7. a load balancer in front of the HTTP service.

That gives you a clean separation between:

  • Nomad as scheduler;
  • PostgreSQL as durable state;
  • Serf as Nomatron server membership; and
  • the load balancer as the stable public entry point.

Common Pitfalls

These are the most common problems when Nomatron is first moved into Nomad:

ProblemWhat it usually means
All three Nomatron servers land on one clientdistinct_hosts or equivalent placement rules are missing.
The UI works but agents cannot connectPort 4650 is not exposed or routed correctly.
Servers never form a clusterSerf advertise_addr or retry_join is wrong, or port 7946 is blocked for TCP or UDP.
Allocation fails with licensing cluster_key is required for connected mode or NOMATRON_ENCRYPTION_KEY is requiredThe Nomad Variable is missing an item, or the env template did not render.
Service is healthy locally but not externallyserver.api_addr does not match the public hostname and scheme.
Secrets are duplicated everywhereThe job relies on inline values instead of templates plus a secret source.
Upgrades are noisy or riskyUpdate strategy and health checks are too weak for a control-plane service.

After this page, the natural next pages are: