Technical skill

Nomad

Tell a cluster what should be running

Suppose you want two copies of a small website running in a group of computers. You could start each by hand, but then you would also have to track where they run and whether they are still running. Nomad is a scheduler: software that assigns workloads to computers in a cluster, a group of connected machines. You describe the workload you want; Nomad servers choose a placement, and Nomad clients run it.

Here is a job file that requests two copies of an Nginx service:

job "web-demo" {
  datacenters = ["dc1"]
  type = "service"

  group "web" {
    count = 2

    task "nginx" {
      driver = "docker"

      config {
        image = "nginx:alpine"
      }

      resources {
        cpu    = 250
        memory = 128
      }
    }
  }
}

This file uses HCL, a configuration language. job names the workload and type = "service" marks it as a long-running service. The web task group has count = 2, so Nomad should place two copies of the group. Its nginx task uses the Docker driver to start the nginx:alpine image. The resource request is 250 MHz of CPU and 128 MB of memory; Nomad compares those requests with available client resources.

Save the file as web-demo.nomad.hcl. nomad job plan web-demo.nomad.hcl runs a scheduler dry run and shows what a submission would do. It does not change the cluster or reserve the proposed machines, so later placement can differ. nomad job run web-demo.nomad.hcl submits the job. Then nomad job status web-demo and the job's allocations show whether tasks started.

Understand jobs, tasks, and placements

A job is a description of the desired workload. It does not say exactly which machine must run it. Nomad servers accept job submissions, keep cluster state, and calculate placements. Clients report their resources and installed task drivers, then execute work assigned to them. A node is a machine in the cluster; in Nomad terminology it usually refers to a client.

A job can contain task groups, and each group can contain one or more tasks. Tasks in a group are placed together on the same client. A task says what to run, which driver to use, and the configuration and resources it needs. The Docker driver is only one option; supported drivers can start containers or other programs.

An allocation records the placement of a task group on a particular client. If count requests several copies, Nomad creates multiple allocations. An evaluation is Nomad's assessment of a job change and the scheduling work it requires. These records help explain a pending job: constraints may rule out available clients, requested resources may not fit, or a client may be unavailable.

Check the plan and the running tasks

Jobs can also describe service registration, health checks, rolling updates, placement constraints and preferences, volumes, and settings for a particular job type or task driver. A Docker task needs the Docker driver configured on its client and access to the named image. Nomad cannot repair a missing image or a faulty application.

Resource requests guide placement; they are not the same as measured usage. Keep them realistic. A health check should test behavior that matters, while allocation events and logs can help explain failed placement or startup. Validate the job file and review the plan before submitting an update to a running workload.

Interactive exercises

Materials

Skillsets
Skillset Devops preview
image descriptionDevops
by Dio
3 users
Skillset Linux administrator preview
image descriptionLinux administrator
by Infinite Education
3080 users
Skillset Devops preview
image descriptionDevops
by Ajay Kumar
2004 users
Skillset DevOps engineer preview
image descriptionDevOps engineer
by Infinite Education
1211 users
Skillset DevOps preview
image descriptionDevOps
by Federico Cordone
3 users
Do you know that ...?
Any useful or interesting facts about the skill. Any peace of information would be useful