liveBook · Manning

Nomad

As explained in Road to Kubernetes

HashiCorp Nomad is a workload orchestrator for deploying and managing applications and services across clusters.

Nomad runs container workloads across a cluster of virtual machines. It is an alternative to Kubernetes and Docker Swarm, but its configuration uses HashiCorp Configuration Language (HCL) rather than YAML. HCL is declarative: you describe the cluster and the work it should run. section 9.0 section 9.2

Four terms make a small Nomad deployment easier to follow:

  • A server maintains cluster state and schedules work. section 9.2.1
  • A client is a machine that runs work assigned by a server. section 9.2.1
  • A task runs a container; a job defines a collection of tasks to deploy. section 9.2.1

For a starter cluster, prepare three virtual machines: one server and two clients. Install Nomad and Docker Engine on each. The server configuration enables server mode, disables client mode, and advertises its private IP address so other nodes can reach it. section 9.2.1 section 9.2.2 section 9.2.3

Listing 9.6 Nomad server configuration
# Located at /etc/nomad.d/nomad.hcl
data_dir = "/opt/nomad/data"

bind_addr = "0.0.0.0"

name = "nomad-server-1"

advertise {
    http = "192.168.204.96"
    rpc = "192.168.204.96"
    serf = "192.168.204.96"
}

server {
    enabled = true
    bootstrap_expect = 1 # number of servers
}

client {
    enabled = false
}

Use this HCL configuration as the server pattern; replace the advertised address with your server’s private IP. section 9.2.3

Each client instead enables client mode, disables server mode, and points to the server’s private IP and port. Start the Nomad service on both clients, then check that they have joined the cluster. The server’s UI can also show clients and jobs. section 9.2.4 section 9.3

Listing 9.7 Nomad Client configuration
# Located at /etc/nomad.d/nomad.hcl

data_dir = "/opt/nomad/data"

bind_addr = "0.0.0.0"

name = "nomad-client"

server {
    enabled = false
}

client {
    enabled = true
    options = {
        "driver.raw_exec.enable" = "1"
        "docker.privileged.enabled" = "true"
    }
    servers = ["192.168.204.96:4647"]
    server_join {
        retry_join = ["192.168.204.96:4647"]
    }
}


ui {
    enabled = false
}

The client configuration shows the server address and retry-join settings; give each client its own name. section 9.2.4

Run a container job

Define a job containing a group, then a task using the Docker driver and a publicly accessible Python application image. In the server UI, choose Run Job, paste the HCL, inspect the Plan, and then run it. A job can later contain both Python and JavaScript tasks; network ports and service definitions make those applications reachable and visible as services. Private images need additional configuration. section 9.2.5

Listing 9.8 Nomad job definition
job "a_unique_job_name" {
  group "unique_group_per_job" {
    task "unique_task_per_group" {
      driver = "docker"
      config {
        image = "codingforentrepreneurs/rk8s-py"
      }
    }
  }
}

This minimal job makes the job → group → task nesting and Docker image declaration concrete. section 9.2.5

How Road to Kubernetes covers it

How deep it goes
Walks through cluster setup, HCL configuration, and UI-based job deployment; defers private-image configuration and detailed UI operation.
Examples
Uses a one-server, two-client cluster and Python and JavaScript container jobs with port mappings and service definitions.
What it assumes
Assumes access to virtual machines and container images; introduces Nomad roles and installation before deploying a job.
What you can do after
Operate/configure it: assemble a small cluster, submit and plan a Docker job in the UI, and stop or purge it.
How it connects
Connects HCL jobs to Docker containers and compares server, client, task, and job roles with Kubernetes concepts.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Road to Kubernetes. The section links point to the parts of the book it draws on.