Featured image of post Nomad Odyssey: Navigating the HashiCorp Universe with Confidence Part-I

Nomad Odyssey: Navigating the HashiCorp Universe with Confidence Part-I

Introduction

It can be daunting when first looking at a new piece of software. There’s a balance to be struck between getting up and running as quickly as possible, while also trying to make sure you understand what it is you are doing. Getting started guides often try to jump to the advanced use cases before you are truly comfortable with the basics, let alone everything in between!

This guide will walk you through, providing a basic understanding of Nomad.What you are doing along the way and where to find more information.

What Is Nomad?

According to its website Nomad is: A simple and flexible workload orchestrator to deploy and manage containers and non-containerized applications across on-prem and clouds at scale.

Nomad is a scheduler that manages tasks like ensuring a specified number of instances of a particular image are running and maintains their availability across a diverse cluster of hosts. Your scheduler will take information like “I want N copies of image X running” and handle the execution and upkeep of these containers on a cluster of different hosts.

If a container crashes, Nomad automatically detects and reschedules it. For Example, if an Azure instance with three microservice instances crashes, Nomad redistributes these instances to other machines in your cluster (if capacity is available).

When updating your microservices from version A to version B while maintaining uptime, you’ll need a Blue/Green or rolling deployment. Your scheduler handles and executes these types of tasks.

Nomad architecture:

I’ll do my best to simplify everything, but I strongly recommend checking out this website for more details.

Nomad consists of two components: Server and Client.

Server - A Server manages all jobs and clients, runs evaluations and creates task allocations. There is a cluster of servers per region and they manage all jobs and clients, run evaluations, and create task allocations. The servers replicate data between each other and perform leader election to ensure high availability. Servers federate across regions to make Nomad globally aware.

Client - A Client of Nomad is a machine that tasks can be run on. All clients run the Nomad agent. The agent is responsible for registering with the servers, watching for any work to be assigned and executing tasks. The Nomad agent is a long-lived process which interfaces with the servers.

Single Region Architecture:

Alt text

Within each region, we have both clients and servers. Servers are responsible for accepting jobs from users, managing clients, and computing task placements. Each region may have clients from multiple datacenters, allowing a small number of servers to handle very large clusters.

In some cases, for either availability or scalability, you may need to run multiple regions. Nomad supports federating multiple regions together into a single cluster. At a high level, this setup looks like this:

Alt text

Key Definitions

The Nomad job specification defines the schema for Nomad jobs. Job files are written in the HashiCorp Configuration Language (HCL),which strikes a nice balance between human readable and editable code, and is machine-friendly.

There are many pieces to the job specification although not all are required. Some of the key ones are below.

Job

A specification provided by users that declares a workload for Nomad.

# This declares a job named "docs". There can
# be exactly one job declaration per job file
job "docs" {
  ...
}

Task Group

A set of tasks that must be run together on the same client node. Multiple instances of a task group can run on different nodes.

job "docs" {
  group "web" {
    # All tasks in this group will run on 
    # the same node
    ...
  }
  group "logging" {
    # These tasks must also run together 
    # but may be a different node from web
    ...
  }
}

Task

The smallest unit of work in Nomad.

job "docs" {
  group "example" {
    task "server" {
      # ...
    }
  }
}

Task Driver

Represents the basic means of executing your Tasks e.g. Docker, Java, Qemu etc. I strongly recommend checking out this website for more details.

task "server" {
  driver = "docker"
  ...
}

Resources

Describes the requirements a task needs to execute such as memory, network, CPU and more.

job "docs" {
  group "example" {
    task "server" {
      resources {
        cpu    = 100
        memory = 256

        network {
          mbits = 100
          port "http" {}
          port "ssh" {
            static = 22
          }
        }

        device "nvidia/gpu" {
          count = 2
        }
      }
    }
  }
}

Stay tuned for Part II of our Nomad Odyssey - where theory meets practice in the HashiCorp Universe! Continue to Part II

Subscribe for Free

We care about your data in our privacy policy

Privacy Policy