Nomad is the workload orchestrator of HashiCorp: it
schedules containers and processes on a cluster of machines from declarative job files. Stellar
Systems delivers, with the container image, the Nomad job files
that run Stellar Control on it: NATS with JetStream, and the services of the core, their web
editor and simulated targets, in containers of the image stellar-control (Docker driver),
behind a Traefik that finds them with its Nomad provider.
Files#
| File | Content |
|---|---|
agent-containers.hcl | Example of a Nomad agent running Stellar Control in containers: Docker driver with volumes, a private host network for NATS, no raw_exec |
jobs/containers/nats.nomad.hcl | Job nats in a container of the official image, with the resolver of the operator |
jobs/containers/cell.nomad.hcl | Job stellar: one container per component (or the core in one), the simulated targets, routed by Traefik from the tags of its API service |
policies/traefik.hcl | ACL policy of the Nomad provider of Traefik: it reads the services and their tags |
Deploy#
On a Nomad agent configured like agent-containers.hcl, with the operator, the account and the
users of NATS made with nsc (see
NATS and JetStream):
# NATS, on the private network of the clients
nomad job run \
-var data_dir=/srv/stellar/nats/data \
-var resolver_conf=/etc/stellar/nats/resolver.conf \
-var resolver_dir=/srv/stellar/nats/accounts \
-var host_network=private \
jobs/containers/nats.nomad.hcl
curl -fsS http://172.17.0.1:8222/healthz # NATS is up, on the private network
# The secrets of Stellar Control, readable by its job only
nomad var put nomad/jobs/stellar \
services_creds=@admin.creds bootstrap_creds=@bootstrap.creds \
signing_key=@stellar-account-signing.nk account=A…
# Stellar Control
nomad job run \
-var image=<registry>/stellar-control -var tag=<version> \
-var host=control.example.org \
-var repository=/srv/stellar/config \
-var nats_url=nats://172.17.0.1:4222 \
jobs/containers/cell.nomad.hcl
nomad job status stellar # its groups and their allocations
nomad alloc logs <alloc> main # logs of a componentrepository is a configuration repository (a Git working copy) on every client that may run
the job; the containers mount it read only. Without NATS authentication (a trial), run the job
with -var secrets=false and skip the variable.
Containers#
Stellar Control runs in containers of the image stellar-control, one per component (or the core
in one, all_in_one=true) and one per simulated target:
- Configuration. Before the reconciler starts, the prestart task
publish-configrunsstellar compile <repository> --publish <nats>with the CLI of the image: every restart of the reconciler group publishes the configuration repository as it is. - Order. Nomad does not order jobs: run Stellar Control once NATS answers. A component that cannot reach NATS retries its connection, and a failed allocation is rescheduled every 10 s.
- Routes from tags. The service
<job>-apicarries the router of Traefik: its host, entry point, TLS and certificate resolver. - Ports of their own. Each API instance listens on 8080 in its container, published on a
port chosen by Nomad; Traefik spreads the requests among them. Its health check is
GET /v1/openapi.json. The editor is found by the API through its service<job>-editor. - Hardened containers. Read-only root file system, no capabilities,
no-new-privileges, the user of the image (10001); the secrets are files of that user, mode 0400. The only host path is the configuration repository, mounted read only (read and write for the editor): the Docker plugin needsvolumes { enabled = true }. - NATS off the public address. The components reach NATS at
nats_url: its ports are published on the host networkhost_networkof the clients, a private one on a host with a public address (agent-containers.hcl: the bridge of Docker). - Metrics. Each component serves
/metricsand/healthzon port 9100 of its container, published as the service<job>-metrics. See Observability.
Variables of the jobs#
nats (jobs/containers/nats.nomad.hcl)
| Variable | Default | Meaning |
|---|---|---|
data_dir | — | JetStream storage on the client, kept across restarts |
resolver_conf | — | Operator and resolver configuration (resolver.conf of nsc generate config) |
resolver_dir | — | Directory of the accounts of a full resolver, as written in resolver_conf; an existing directory with a memory resolver |
host_network | default | Host network of the clients where the ports are published (default: the address of the client) |
port, monitoring_port | 4222, 8222 | Client and monitoring ports |
tls_dir | empty (no TLS) | Directory of ca.pem, server.pem and server-key.pem |
tls_verify | false | Require client certificates signed by the CA (mTLS) |
leafnode_port | 0 (none) | Port of the leaf nodes of the benches, with TLS |
websocket_port | 0 (none) | NATS WebSocket for leaf nodes and clients behind firewalls (443 in production), with TLS |
encrypt | false | JetStream encrypts its files, with the key of the Nomad variable nomad/jobs/nats (see Encryption at rest) |
nats_version | 2.12.15 | Tag of the image nats |
stellar (jobs/containers/cell.nomad.hcl)
| Variable | Default | Meaning |
|---|---|---|
image, tag | stellar-control, latest | Image of the components; an immutable tag in production (latest is pulled at every start) |
host | — | Host name of Stellar Control, routed by Traefik |
repository | — | Configuration repository on the clients |
config | archive of 7 days, JSON logs | Global configuration of the components, in YAML; the job sets NATS, the API and the metrics through the environment |
nats_url, nats_ca | the address of the client, port 4222; empty | NATS server, reached from the containers; its CA |
secrets | true | Credentials, signing key and account from the Nomad variable secrets_path (items services_creds, bootstrap_creds, signing_key, account, and forge_token optionally) |
secrets_path | nomad/jobs/stellar | That variable, readable by the job only (nomad/jobs/<job>) |
all_in_one | false | The core in one container (stellar-control, group mcs) |
counts | 1 per group (0 for the editor) | Instances of each group at deployment |
memory | {default = 128, mcs = 384, editor = 256, simulators = 64} | Memory of the containers in MB, by group |
storage | 0 | JetStream storage of the deployment in bytes (archive.max_bytes), see Storage of a deployment; 0: bounded by age only |
editor_repository, editor_path | empty, . | Web editor: its Git remote as seen from its container (/srv/stellar/config, the configuration repository, mounted read and write for it) |
editor_forge | empty (that of config) | Forge of the editor: direct publishes a proposed draft at once |
simulators | two example targets | Simulated targets, one container each (simulation, target, gateway, driver); the defaults are the targets sim-1 and psu-sim-1 of the example configuration |
auth_issuer, auth_audience, auth_organization, auth_client_id, auth_cli_client_id, auth_roles_prefix | empty, stellar: for the prefix | OpenID Connect provider of the users (see Identity and Roles); empty issuer: declared identities, no sign-in |
traefik_entrypoint | websecure | Entry point of Traefik |
traefik_certresolver | empty | Certificate resolver; empty, the default certificate of Traefik |
traefik_wildcard | empty | Wildcard domain of the certificate (*.example.org) |
rootless | false | A Nomad client not run as root with a rootless engine (Podman, a development machine): the components run as root in their containers, without capabilities, to read their secrets |
Scaling#
Every group scales from 0 to its maximum with nomad job scale stellar <group> <n>; the
initial counts come from the counts variable.
| Group | Instances | How they share the work |
|---|---|---|
api | 0 to 3 | All active; Traefik spreads the requests among them |
executor | 0 to 3 | All active: runs spread by identifier, targets held by leases |
scheduler | 0 to 3 | All active: each run submitted once |
reconciler | 0 to 3 | One leader, the others stand by |
compute, alarms, transfers | 0 to 3 | One active, the others take over within leader_ttl |
mcs | 0 to 1 | The core in one container, with all_in_one=true |
editor | 0 to 1 | Drafts are working copies in its allocation |
simulators | 0 to 1 | One container per simulated target |
At 0, a component stops: api at 0 closes the web application and the CLI. See
Running the Services.
With all_in_one=true, stellar-control runs in the group mcs beside the simulators: about a
quarter of the memory of the separate services.
TLS#
A deployment uses the certificates of its own CA: tls_dir (ca.pem, server.pem,
server-key.pem) and tls_verify (mTLS) for the nats job, nats_ca for Stellar Control,
and leafnode_port, websocket_port for the benches and the edges on other networks. Clients
then use tls://<host>:4222 and the CA (STELLAR_NATS_CA), or wss://<host>:<websocket_port>
through the WebSocket.
Reverse proxy#
Traefik serves the API, the web application and their WebSockets over HTTPS. Its Nomad
provider finds the API by the tags of its service, with a token of the policy
policies/traefik.hcl:
providers:
nomad:
endpoint:
address: http://172.17.0.1:4646 # the API of Nomad, on the private network
token: <a token of the policy traefik>
namespaces: [default]
exposedByDefault: falseIn production it listens on 80 and 443 and gets its certificates from an ACME certificate
resolver (traefik_certresolver). The CLI checks the certificate against the system roots, or
with STELLAR_API_CA when it is not signed by a public CA:
STELLAR_API_CA=/etc/stellar/tls/ca.pem \
stellar send sim-1 'tcu[TCU1].ping' --api https://control.example.orgSecrets#
No secret is written in a job or in a repository: each lives in a Nomad variable (encrypted at rest by Nomad, readable by the tasks of its job only) or with the operator of NATS.
| Secret | Where | Read by | Rotation |
|---|---|---|---|
| Operator key of NATS | With nsc, offline | Whoever makes the accounts | A new operator: every account signed again |
| Signing key of the account, credentials of the services and bootstrap credentials | nomad/jobs/stellar (secrets_path) | The job stellar (secrets=true) | New values in the variable, then the job run again |
| Forge token of the editor | forge_token in the same variable | The editor | Set it again: the editor restarts with it |
| JetStream key | nomad/jobs/nats (jetstream_key, with encrypt=true) | NATS | See Encryption at rest |
| TLS keys | Files of tls_dir on the Nomad clients, or ACME | NATS, Traefik | A new certificate in place and a restart; ACME renews by itself |
Keep the data directory of JetStream, the configuration repository and the data directory of Nomad on encrypted disks. See TLS, Encryption and Secrets.