Skip to content

Deploying a Nomad 1.7 server cluster + client pool on Ubuntu 22.04 (TLS, ACLs, Consul-integrated)

Stand up a three-node HashiCorp Nomad 1.7 server cluster on Ubuntu 22.04 with mutual TLS, ACL bootstrap, gossip encryption, and a Consul-integrated client pool — the full installer.

You inherit a workload that started life as a docker compose up on one VM, grew into eight VMs each running its own compose file, and is now at the point where nobody remembers which host owns which service. The team has been told to “go to Kubernetes” and has spent four months arguing about CNIs. You read the actual workload — twenty long-running services, a handful of cron jobs, no service mesh requirement, no pod-level isolation requirement — and realize the right tool is the one nobody mentioned in the meeting: HashiCorp Nomad. Three small server nodes elect a leader, a client pool runs the workload, you keep your existing Docker images, and the entire control plane fits on a laptop. This installer is what gets the control plane up correctly the first time.

What’s happening

Nomad is a scheduler. The server cluster runs Raft, holds the desired-state of every job, and elects one leader to issue placements. The client nodes register with the servers, advertise their resources (CPU, memory, attached drivers), and pull job allocations to run with the matching task driver — usually docker, sometimes exec, occasionally java or raw_exec. Three servers is the minimum that survives one failure; five is the next quorum size up. Clients are horizontal and stateless from the scheduler’s point of view — drain one, add ten, the workload reshuffles.

The pieces that surprise people coming from Kubernetes are gossip encryption (a shared key encrypts the Serf cluster gossip — without it, anyone who can talk to the gossip port can poison membership), the ACL system (off by default, on in production, bootstrap token is a one-time event you cannot redo cleanly), and mutual TLS (Nomad does not assume a service mesh; if you want clients and servers to authenticate each other and the agent traffic encrypted, you generate a CA and issue per-node certs). Consul is optional but heavily integrated: service registration, health checks, DNS resolution, and connect-sidecar all flow through Consul if you wire it up. The installer below assumes Consul is already running (separate article) and configures Nomad to use it.

How to verify

A healthy three-server cluster looks like this:

nomad server members
# Name         Address      Port  Status  Leader  Raft Version  Build  Datacenter  Region
# nomad-s01.global  10.20.0.11   4648  alive   true    3             1.7.7  dc1         global
# nomad-s02.global  10.20.0.12   4648  alive   false   3             1.7.7  dc1         global
# nomad-s03.global  10.20.0.13   4648  alive   false   3             1.7.7  dc1         global

Exactly one leader. All three at the same Raft Version. No nodes in failed state.

Client side:

nomad node status
# ID        DC   Name        Class   Drain  Eligibility  Status
# 7a4b...   dc1  nomad-c01   linux   false  eligible     ready
# 9c1d...   dc1  nomad-c02   linux   false  eligible     ready
# 5e2f...   dc1  nomad-c03   linux   false  eligible     ready

ready is the only acceptable state for a client serving production. initializing means the driver fingerprint hasn’t completed; down means the heartbeat to the servers has failed. Check the agent log if anything is stuck.

ACLs are on if this command requires a token:

nomad acl token self
# Errors with "ACL token not provided" if the system is bootstrapped and you didn't export NOMAD_TOKEN

TLS is on if you can’t talk over HTTP:

curl -s http://127.0.0.1:4646/v1/status/leader
# curl: (52) Empty reply from server
curl -s --cacert /etc/nomad.d/tls/nomad-ca.pem https://127.0.0.1:4646/v1/status/leader
# "10.20.0.11:4647"

Gossip key is set if it shows up in the running config:

sudo nomad config validate /etc/nomad.d/ 2>&1 | head -5
# Should report no errors. Run on each server.

The fix

The installer below is split into two scripts: one for the three server nodes (setup-nomad-server.sh) and one for the client pool (setup-nomad-client.sh). Run the server script first on all three servers in parallel — they will join via the retry_join block. Then run the client script on each client node.

The server script: hardens the base OS (UFW, fail2ban, unattended-upgrades, SSH key-only), installs Nomad 1.7 from the HashiCorp APT repo, generates and distributes the gossip key, lays down server config with TLS paths, sets up the systemd unit with LimitNOFILE=65536 and Capabilities=CAP_IPC_LOCK, and waits for leader election before exiting.

Generate the gossip key and CA on a workstation first:

# On your workstation
nomad operator gossip keyring generate
# Save the output — paste it into GOSSIP_KEY below

# CA + per-node certs
nomad tls ca create
nomad tls cert create -server -region global -additional-dnsname server.global.nomad
nomad tls cert create -client
# Distribute nomad-ca.pem, global-server-nomad.pem, global-server-nomad-key.pem to servers
# Distribute nomad-ca.pem, global-client-nomad.pem, global-client-nomad-key.pem to clients

Then the server installer:

#!/usr/bin/env bash
set -euo pipefail

### Ubuntu 22.04 Nomad 1.7 server installer
### Run on each of the 3 server nodes after editing the variables below
### Assumes nomad-ca.pem and per-node server certs are already present at /etc/nomad.d/tls/

if [[ "$(id -u)" -ne 0 ]]; then
  echo "Run as root."
  exit 1
fi

# === EDIT PER NODE ===
NODE_NAME="nomad-s01"
NODE_IP="10.20.0.11"
PEER_IPS=("10.20.0.11" "10.20.0.12" "10.20.0.13")
DATACENTER="dc1"
REGION="global"
GOSSIP_KEY="REPLACE_WITH_GENERATED_GOSSIP_KEY"
CONSUL_ADDR="127.0.0.1:8500"
CONSUL_TOKEN="REPLACE_WITH_CONSUL_AGENT_TOKEN"
# =====================

echo
echo "========================================"
echo "Nomad server ${NODE_NAME} (${NODE_IP})"
echo "========================================"
echo

echo "==> Updating base OS"
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get -y upgrade
apt-get -y install ca-certificates curl wget gnupg lsb-release ufw \
  fail2ban unattended-upgrades chrony jq socat net-tools dnsutils \
  software-properties-common apt-transport-https

systemctl enable --now chronyd

echo "==> UFW firewall"
ufw --force reset
ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp
ufw allow from 10.20.0.0/16 to any port 4646 proto tcp  # HTTP API
ufw allow from 10.20.0.0/16 to any port 4647 proto tcp  # RPC
ufw allow from 10.20.0.0/16 to any port 4648            # Serf (TCP+UDP)
ufw --force enable

echo "==> Hardening SSH"
sed -i 's|^[#[:space:]]*PermitRootLogin.*|PermitRootLogin prohibit-password|' /etc/ssh/sshd_config
sed -i 's|^[#[:space:]]*PasswordAuthentication.*|PasswordAuthentication no|' /etc/ssh/sshd_config
sshd -t && systemctl restart ssh

echo "==> fail2ban + unattended-upgrades"
cat > /etc/fail2ban/jail.d/sshd.local <<'FAIL2BAN'
[sshd]
enabled = true
port = ssh
backend = systemd
maxretry = 4
findtime = 10m
bantime = 1h
FAIL2BAN
systemctl enable --now fail2ban

cat > /etc/apt/apt.conf.d/20auto-upgrades <<'AUTOUP'
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
APT::Periodic::AutocleanInterval "7";
AUTOUP

echo "==> Adding HashiCorp APT repository"
wget -O- https://apt.releases.hashicorp.com/gpg | \
  gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] \
  https://apt.releases.hashicorp.com $(lsb_release -cs) main" \
  > /etc/apt/sources.list.d/hashicorp.list
apt-get update
apt-get -y install nomad=1.7.7-1

echo "==> Locking Nomad to 1.7.7"
apt-mark hold nomad

echo "==> Sysctl tweaks for cluster gossip"
cat > /etc/sysctl.d/99-nomad.conf <<'SYSCTL'
net.core.somaxconn = 4096
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.ip_local_port_range = 10240 65535
fs.file-max = 2097152
SYSCTL
sysctl --system

echo "==> Writing Nomad server config"
mkdir -p /etc/nomad.d/tls /var/lib/nomad
chown -R nomad:nomad /var/lib/nomad
chmod 755 /etc/nomad.d
chmod 700 /etc/nomad.d/tls

# Expect these files to already be present on the box:
#   /etc/nomad.d/tls/nomad-ca.pem
#   /etc/nomad.d/tls/global-server-nomad.pem
#   /etc/nomad.d/tls/global-server-nomad-key.pem
chmod 600 /etc/nomad.d/tls/*.pem
chown -R nomad:nomad /etc/nomad.d/tls

cat > /etc/nomad.d/nomad.hcl <<EOF
datacenter = "${DATACENTER}"
region     = "${REGION}"
name       = "${NODE_NAME}"
data_dir   = "/var/lib/nomad"
log_level  = "INFO"
bind_addr  = "0.0.0.0"

advertise {
  http = "${NODE_IP}:4646"
  rpc  = "${NODE_IP}:4647"
  serf = "${NODE_IP}:4648"
}

server {
  enabled          = true
  bootstrap_expect = 3
  encrypt          = "${GOSSIP_KEY}"

  retry_join = [
    "${PEER_IPS[0]}",
    "${PEER_IPS[1]}",
    "${PEER_IPS[2]}"
  ]

  raft_protocol = 3
  default_scheduler_config {
    scheduler_algorithm = "spread"
    memory_oversubscription_enabled = false
    preemption_config {
      batch_scheduler_enabled    = true
      system_scheduler_enabled   = true
      service_scheduler_enabled  = true
      sysbatch_scheduler_enabled = true
    }
  }
}

acl {
  enabled        = true
  token_ttl      = "30s"
  policy_ttl     = "60s"
  replication_token = ""
}

tls {
  http = true
  rpc  = true

  ca_file   = "/etc/nomad.d/tls/nomad-ca.pem"
  cert_file = "/etc/nomad.d/tls/global-server-nomad.pem"
  key_file  = "/etc/nomad.d/tls/global-server-nomad-key.pem"

  verify_server_hostname = true
  verify_https_client    = false
}

consul {
  address    = "${CONSUL_ADDR}"
  token      = "${CONSUL_TOKEN}"
  auto_advertise      = true
  server_auto_join    = true
  client_auto_join    = true
  server_service_name = "nomad"
  client_service_name = "nomad-client"
}

telemetry {
  publish_allocation_metrics = true
  publish_node_metrics       = true
  prometheus_metrics         = true
  disable_hostname           = true
}

ui {
  enabled = true
  consul {
    ui_url = "http://${NODE_IP}:8500/ui"
  }
}
EOF

chown -R nomad:nomad /etc/nomad.d
chmod 640 /etc/nomad.d/nomad.hcl

echo "==> systemd unit"
cat > /etc/systemd/system/nomad.service <<'NOMAD'
[Unit]
Description=Nomad
Documentation=https://developer.hashicorp.com/nomad
Wants=network-online.target
After=network-online.target

[Service]
User=nomad
Group=nomad
ExecReload=/bin/kill -HUP $MAINPID
ExecStart=/usr/bin/nomad agent -config=/etc/nomad.d
KillMode=process
KillSignal=SIGINT
LimitNOFILE=65536
LimitNPROC=infinity
Restart=on-failure
RestartSec=2
TasksMax=infinity
OOMScoreAdjust=-1000
AmbientCapabilities=CAP_IPC_LOCK

[Install]
WantedBy=multi-user.target
NOMAD

id -u nomad >/dev/null 2>&1 || useradd --system --home /etc/nomad.d --shell /bin/false nomad

systemctl daemon-reload
systemctl enable --now nomad

echo "==> Waiting for leader election (up to 90s)"
for i in {1..45}; do
  if nomad server members 2>/dev/null | awk 'NR>1 && $5=="true"' | grep -q .; then
    echo "Leader elected."
    break
  fi
  sleep 2
done

echo
echo "========================================"
echo "DONE — node ${NODE_NAME}"
echo "========================================"
echo
echo "Listeners:"
ss -lntp | grep -E ':(4646|4647|4648)\b' || true
echo
echo "Server members (will be partial until all 3 are up):"
nomad server members 2>/dev/null || true
echo
echo "Next:"
echo "  Repeat on the other 2 server nodes with their NODE_NAME / NODE_IP."
echo "  Once all 3 servers report 'alive', bootstrap ACLs from ONE server:"
echo "    nomad acl bootstrap"
echo "  Save the SecretID — there is no second chance."

The client installer below assumes the server cluster is already up. It installs Docker + the CNI plugins + Nomad as a client, joins via retry_join, advertises to Consul, and locks the file descriptor limit high enough for moderately busy workloads.

#!/usr/bin/env bash
set -euo pipefail

### Ubuntu 22.04 Nomad 1.7 client installer
### Run on each client node after editing the variables below
### Assumes client TLS cert + key are already at /etc/nomad.d/tls/

if [[ "$(id -u)" -ne 0 ]]; then
  echo "Run as root."
  exit 1
fi

# === EDIT PER NODE ===
NODE_NAME="nomad-c01"
NODE_IP="10.20.0.21"
SERVER_IPS=("10.20.0.11" "10.20.0.12" "10.20.0.13")
DATACENTER="dc1"
REGION="global"
GOSSIP_KEY="REPLACE_WITH_GENERATED_GOSSIP_KEY"
CONSUL_ADDR="127.0.0.1:8500"
CONSUL_TOKEN="REPLACE_WITH_CONSUL_AGENT_TOKEN"
# =====================

export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get -y install ca-certificates curl wget gnupg lsb-release ufw \
  fail2ban unattended-upgrades chrony jq net-tools dnsutils \
  software-properties-common apt-transport-https

systemctl enable --now chronyd

echo "==> Installing Docker engine"
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
  -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] \
  https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" \
  > /etc/apt/sources.list.d/docker.list
apt-get update
apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin

cat > /etc/docker/daemon.json <<'DAEMON'
{
  "log-driver": "json-file",
  "log-opts": { "max-size": "50m", "max-file": "3" },
  "live-restore": true,
  "userland-proxy": false
}
DAEMON
systemctl enable --now docker

echo "==> Installing HashiCorp repo + Nomad"
wget -O- https://apt.releases.hashicorp.com/gpg | \
  gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] \
  https://apt.releases.hashicorp.com $(lsb_release -cs) main" \
  > /etc/apt/sources.list.d/hashicorp.list
apt-get update
apt-get -y install nomad=1.7.7-1
apt-mark hold nomad

echo "==> CNI plugins"
ARCH=$(dpkg --print-architecture)
mkdir -p /opt/cni/bin
curl -L -o /tmp/cni.tgz \
  "https://github.com/containernetworking/plugins/releases/download/v1.4.0/cni-plugins-linux-${ARCH}-v1.4.0.tgz"
tar -C /opt/cni/bin -xzf /tmp/cni.tgz
rm /tmp/cni.tgz

echo "==> UFW firewall"
ufw --force reset
ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp
ufw allow from 10.20.0.0/16 to any port 4646 proto tcp
ufw allow from 10.20.0.0/16 to any port 4647 proto tcp
ufw allow from 10.20.0.0/16 to any port 4648
ufw allow from 10.20.0.0/16 to any port 20000:32000 proto tcp  # dynamic ports
ufw allow from 10.20.0.0/16 to any port 20000:32000 proto udp
ufw --force enable

mkdir -p /etc/nomad.d/tls /var/lib/nomad /opt/nomad/data
chown -R nomad:nomad /var/lib/nomad /opt/nomad/data
chmod 700 /etc/nomad.d/tls
chmod 600 /etc/nomad.d/tls/*.pem || true

cat > /etc/nomad.d/nomad.hcl <<EOF
datacenter = "${DATACENTER}"
region     = "${REGION}"
name       = "${NODE_NAME}"
data_dir   = "/var/lib/nomad"
log_level  = "INFO"
bind_addr  = "0.0.0.0"

advertise {
  http = "${NODE_IP}:4646"
  rpc  = "${NODE_IP}:4647"
  serf = "${NODE_IP}:4648"
}

client {
  enabled = true

  servers = [
    "${SERVER_IPS[0]}:4647",
    "${SERVER_IPS[1]}:4647",
    "${SERVER_IPS[2]}:4647"
  ]

  network_interface = "eth0"

  reserved {
    cpu    = 200
    memory = 512
    disk   = 1024
  }

  host_volume "tmp" {
    path      = "/opt/nomad/host_volumes/tmp"
    read_only = false
  }
}

plugin "docker" {
  config {
    allow_privileged = false
    volumes {
      enabled = true
    }
    gc {
      image       = true
      image_delay = "12h"
      container   = true
    }
  }
}

acl {
  enabled = true
}

tls {
  http                   = true
  rpc                    = true
  ca_file                = "/etc/nomad.d/tls/nomad-ca.pem"
  cert_file              = "/etc/nomad.d/tls/global-client-nomad.pem"
  key_file               = "/etc/nomad.d/tls/global-client-nomad-key.pem"
  verify_server_hostname = true
  verify_https_client    = false
}

consul {
  address       = "${CONSUL_ADDR}"
  token         = "${CONSUL_TOKEN}"
  auto_advertise = true
  client_auto_join = true
}

telemetry {
  publish_allocation_metrics = true
  publish_node_metrics       = true
  prometheus_metrics         = true
  disable_hostname           = true
}
EOF

chown -R nomad:nomad /etc/nomad.d
chmod 640 /etc/nomad.d/nomad.hcl

cat > /etc/systemd/system/nomad.service <<'NOMAD'
[Unit]
Description=Nomad
Wants=network-online.target docker.service
After=network-online.target docker.service

[Service]
User=root
Group=root
ExecReload=/bin/kill -HUP $MAINPID
ExecStart=/usr/bin/nomad agent -config=/etc/nomad.d
KillMode=process
KillSignal=SIGINT
LimitNOFILE=65536
LimitNPROC=infinity
Restart=on-failure
RestartSec=2
TasksMax=infinity
OOMScoreAdjust=-1000

[Install]
WantedBy=multi-user.target
NOMAD

systemctl daemon-reload
systemctl enable --now nomad

echo "==> Waiting for client to register with servers"
for i in {1..30}; do
  if curl -fs --cacert /etc/nomad.d/tls/nomad-ca.pem \
       --cert /etc/nomad.d/tls/global-client-nomad.pem \
       --key  /etc/nomad.d/tls/global-client-nomad-key.pem \
       "https://${NODE_IP}:4646/v1/agent/self" >/dev/null 2>&1; then
    break
  fi
  sleep 2
done

echo
echo "========================================"
echo "Client ${NODE_NAME} ready"
echo "========================================"
echo
echo "From any server:"
echo "  nomad node status"
echo "Should show ${NODE_NAME} as 'ready'."

Once all servers are up and all clients are registered, bootstrap the ACL system from a single server, exactly once:

nomad acl bootstrap
# Accessor ID:  xxxxx
# Secret ID:    yyyyy  <-- save this; it is your management token

Lock the management token in your secrets manager — it is the only token that can create other tokens. Then write a least-privilege policy for your CI pipeline and your operators, and use those tokens for daily work, not the bootstrap token. The first nomad acl policy apply is what turns the cluster from “we have ACLs technically” into “we have a working authorization model.”

We run this Nomad pattern under Managed Cloud Ops for teams who want the scheduler without owning the upgrade cadence — scoping call or the managed PaaS page for what we operate.