Skip to content
LATEST

🚀 Welcome to Upgradix by Shrash Studio – Your destination for free technology learning and career growth.

Upgradix
Upgradix Code. Learn. Ship.

Scheduling Containers & Binaries with HashiCorp Nomad

Orchestrate containerized apps and standalone binaries on a lightweight scheduler with automatic restarts, bin-packing, and zero-downtime rolling updates.

Scheduling Containers & Binaries with HashiCorp Nomad

Not every workload in your organization is a Docker container. Many teams run a mix of containerized microservices, legacy Java JARs, Go binaries, Python scripts, and batch jobs. Running a full Kubernetes cluster just to orchestrate a handful of services and standalone binaries often adds more operational overhead than value.

HashiCorp Nomad is a single-binary, lightweight workload orchestrator designed for simplicity and scale. It schedules Docker containers, standalone binaries (exec / raw_exec), Java applications, and even VMs using the exact same declarative HCL job specification—complete with automatic restarts, intelligent bin-packing, and zero-downtime rolling updates.

What you will learn
  • How Nomad orchestrates both containers and standalone binaries with a single lightweight binary.
  • Core Nomad concepts: Jobs, Task Groups, Tasks, Allocations, and Bin-Packing.
  • How Nomad handles automatic restarts and zero-downtime rolling updates.
  • Hands-On Lab: Start a local Nomad dev agent, submit a .nomad.hcl job running a web service across multiple allocations, inspect placement with nomad job status, and execute a zero-downtime rolling update.
  • Production best practices, practice exercises, and DevOps interview questions.

1. Why Choose Nomad for Containers & Binaries?

Kubernetes is built around containers and requires a complex control plane (etcd, kube-apiserver, kube-scheduler, kube-controller-manager). Nomad ships as a single binary that acts as both server and client, uses Raft for consensus, and supports pluggable task drivers so you can run containers and native binaries side by side.

Feature HashiCorp Nomad Kubernetes Docker Swarm
Workload Types Containers, binaries (exec), Java, QEMU Containers (OCI) primarily Docker containers only
Operational Footprint Single binary (~100 MB), low RAM Multi-component control plane Built into Docker Engine
Scheduling Strategy Bin-packing or spread out of the box Customizable scheduler Spread by default
Rolling Updates Built-in update stanza + auto-revert Deployment RollingUpdate Service update-config

2. Architecture: Bin-Packing & Zero-Downtime Rolling Updates

When you submit a job, the Nomad Server evaluates resource requirements (CPU, memory, ports) and bin-packs Allocations onto available Nomad Client nodes. During a rolling update, Nomad replaces allocations in controlled batches (max_parallel = 1), waiting for each new allocation to pass health checks before updating the next.

Nomad Scheduler: Bin-Packing & Rolling Update Wave (v1 → v2)

Nomad Server Scheduler & State (Raft) web-app.nomad.hcl count=3 | max_parallel=1 Bin-Packing + Auto-Revert Nomad Client – Container Allocations (Docker Driver) Alloc #1 100MHz / 64MB Rolling v1 → v2 Alloc #2 100MHz / 64MB Rolling v1 → v2 Alloc #3 100MHz / 64MB Rolling v1 → v2 Nomad Client – Native Binaries (exec / raw_exec Driver) ./metrics-agent --port 9100 java -jar worker.jar Rolling Update Progress (Zero Downtime): Healthy before next batch

Nomad bin-packs both Docker containers and native binaries onto client nodes. During a rolling update, each allocation transitions from v1 (blue) to v2 (green) one at a time.

3. Hands-On Lab: Deploy & Rolling-Update a Multi-Allocation Web Service

In this lab, you will start a local Nomad development agent, deploy a web service with 3 allocations using a .nomad.hcl job file, inspect placement and resource allocation, and perform a zero-downtime rolling update.

Prerequisites

  • HashiCorp Nomad 1.7+ installed (nomad version)
  • Docker Engine or Docker Desktop running locally
  • Two terminal windows (one for the Nomad agent, one for CLI commands)

Step 1: Start a local Nomad dev agent

In Terminal 1, launch Nomad in dev mode. This starts a single-node cluster acting as both Server and Client, with the web UI available at http://localhost:4646.

Terminal 1: Start Nomad dev agent

nomad agent -dev -bind 0.0.0.0 -network-interface='{{ GetDefaultInterfaces | attr "name" }}'
Simpler local command: On macOS or Windows with Docker Desktop, running nomad agent -dev without extra flags is usually enough. Verify the agent is ready in Terminal 2 with nomad node status.

Step 2: Write the Nomad job specification

Create a file named web-service.nomad.hcl. This job runs 3 allocations of a lightweight HTTP echo server, configures automatic restarts on failure, and defines a rolling update policy (max_parallel = 1).

File: web-service.nomad.hcl

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

  group "web" {
    count = 3

    # Zero-downtime rolling update policy
    update {
      max_parallel     = 1
      min_healthy_time = "5s"
      healthy_deadline = "2m"
      auto_revert      = true
    }

    # Automatic restart policy on task crash
    restart {
      attempts = 3
      interval = "5m"
      delay    = "10s"
      mode     = "fail"
    }

    network {
      port "http" {
        to = 5678
      }
    }

    service {
      name     = "upgradix-web"
      provider = "nomad"
      port     = "http"

      check {
        type     = "http"
        path     = "/"
        interval = "5s"
        timeout  = "2s"
      }
    }

    task "server" {
      driver = "docker"

      config {
        image = "hashicorp/http-echo:0.2.3"
        ports = ["http"]
        args = [
          "-listen=:5678",
          "-text=Upgradix Nomad Service - Release v1.0"
        ]
      }

      resources {
        cpu    = 100 # MHz
        memory = 64  # MB
      }
    }
  }
}

Step 3: Plan and submit the job

In Terminal 2, validate the job, preview the scheduler plan, and submit it to Nomad.

Terminal 2: Validate, plan, and run

nomad job validate web-service.nomad.hcl
nomad job plan web-service.nomad.hcl
nomad job run web-service.nomad.hcl

Expected output

==> Monitoring evaluation "8a2f1c90"
    Evaluation triggered by job "upgradix-web"
    Allocation "3d19a4b2" created: node "9f81c2e4", group "web"
    Allocation "7c40e1f8" created: node "9f81c2e4", group "web"
    Allocation "b291d5a6" created: node "9f81c2e4", group "web"
    Evaluation status changed: "pending" -> "complete"
==> Evaluation "8a2f1c90" finished with status "complete"

Step 4: Inspect placement and test the running allocations

Use nomad job status to view all 3 allocations, their placement, and their health status.

Inspect job placement

nomad job status upgradix-web

Expected output (abbreviated)

ID            = upgradix-web
Status        = running
Submit Date   = 2026-11-27T19:15:10+05:30

Summary
Task Group  Queued  Starting  Running  Failed  Complete  Lost
web         0       0         3        0       0         0

Allocations
ID        Node ID   Task Group  Version  Desired  Status   Created
3d19a4b2  9f81c2e4  web         0        run      running  25s ago
7c40e1f8  9f81c2e4  web         0        run      running  25s ago
b291d5a6  9f81c2e4  web         0        run      running  25s ago

Check the dynamically assigned port of the first allocation and curl it:

# Replace 3d19a4b2 with one of your allocation IDs
nomad alloc status 3d19a4b2 | grep -A 3 "Allocation Addresses"

Step 5: Execute a zero-downtime rolling update

Now update the -text argument in web-service.nomad.hcl from Release v1.0 to Release v2.0, then submit the updated job.

Update the task args in web-service.nomad.hcl

        args = [
          "-listen=:5678",
          "-text=Upgradix Nomad Service - Release v2.0"
        ]

Run the rolling update and watch deployment progress

nomad job run web-service.nomad.hcl
nomad deployment status -monitor

Expected output

Status        = successful
Description   = Deployment completed successfully

Deployed
Task Group  Auto Revert  Desired  Placed  Healthy  Unhealthy
web         true         3        3       3        0

Because max_parallel = 1 and min_healthy_time = "5s", Nomad updated one allocation at a time, waited for its HTTP health check to pass, and only then replaced the next allocation—keeping the service online throughout the entire rollout.

4. Running a Standalone Binary Alongside Containers

If you want to schedule a compiled Go, Rust, or C# binary without wrapping it in Docker, simply switch the task driver from docker to raw_exec (or exec for chroot/cgroup isolation on Linux):

Example: Standalone binary task

task "native-worker" {
  driver = "raw_exec"

  config {
    command = "/usr/local/bin/my-worker"
    args    = ["--mode=production", "--workers=4"]
  }

  resources {
    cpu    = 200
    memory = 128
  }
}

5. Step-by-Step Execution Breakdown

Step 1 – Evaluation Creation: Running nomad job run registers your HCL spec and triggers a scheduler evaluation.
Step 2 – Bin-Packing Placement: Nomad checks CPU and memory budgets across client nodes and packs the 3 allocations efficiently to maximize hardware utilization.
Step 3 – Service Registration & Health Checks: Nomad's built-in service discovery registers each allocation and polls the HTTP / endpoint every 5 seconds.
Step 4 – Controlled Rolling Update: When v2.0 is submitted, Nomad creates 1 new allocation, waits 5 seconds for it to stay healthy, drains 1 old allocation, and repeats until all 3 run v2.0.
Watch out for raw_exec in production: The raw_exec driver runs binaries directly on the host without filesystem isolation. Enable it only on trusted nodes, and prefer the exec driver on Linux for cgroup and chroot isolation.

6. Hands-On Practice

Beginner Exercise 1: Scale allocations up and down

Change count = 3 to count = 5 in web-service.nomad.hcl, run nomad job run, and verify 5 running allocations using nomad job status upgradix-web.

Intermediate Exercise 2: Test automatic rollback (auto_revert)

Update the HTTP check path in web-service.nomad.hcl to an invalid port or failing command, submit the job, and watch Nomad automatically revert to the last healthy version after healthy_deadline.

Advanced Exercise 3: Add a Canary deployment

Add canary = 1 and auto_promote = false to the update stanza. Submit a v3.0 update, inspect the single canary allocation, and manually promote it with nomad deployment promote <deployment-id>.

7. Interview Questions

Q1. What is the difference between a Nomad Job, Task Group, Task, and Allocation?

Answer: A Job is the top-level specification of desired state. A Task Group is a set of tasks that must run together on the same client node. A Task is the individual unit of work (a container or binary). An Allocation is a single running instance of a Task Group placed on a specific node.

Q2. How does Nomad's bin-packing scheduler differ from a spread scheduler?

Answer: Bin-packing packs allocations densely onto the fewest nodes possible, leaving other nodes free for large workloads or scale-down to save cloud costs. Spread distributes allocations evenly across nodes or failure domains for maximum high availability.

Q3. How does Nomad guarantee zero-downtime rolling updates?

Answer: Through the update stanza. By setting max_parallel, min_healthy_time, and auto_revert = true alongside service health checks, Nomad updates only a small batch of allocations at a time, verifies health before proceeding, and automatically rolls back if a new version fails.

Conclusion

HashiCorp Nomad proves that workload orchestration does not have to be heavy or complicated. With a single binary, you can schedule Docker containers and standalone executables side by side, maximize hardware efficiency with bin-packing, and ship updates safely with built-in rolling deployments and automatic rollbacks.

Try expanding this local lab by pairing Nomad with HashiCorp Consul for full service mesh routing or HashiCorp Vault for dynamic secret injection.

Official Documentation

Upgradix by Shrash Studio – Learn Technology. Build Your Future.

Discussion & Comments

0
Guest mode · Login / Register
Post directly as a guest or log in first.

No comments yet

Start the discussion above — ask a question, share a tip, or reply to a comment.

This article is protected. Printing and saving as PDF are disabled.