HashiCorp Nomad is a powerful orchestration and scheduler tool that can be an easily operated Kubernetes alternative. Nomad provides an orchestrator for containers, virtual machines, and other resources. The de facto standard for a container orchestrator today is Kubernetes. However, Kubernetes is extremely challenging and complex. It requires a specialized skillset that can present a barrier to entry regarding running production workloads in self-hosted clusters.
Latest posts by Brandon Lee (see all)

A container orchestrator is a tool that automates the deployment, management, scaling, and networking of containerized applications. Containerization allows applications to be packaged as self-contained units that can run anywhere, regardless of the underlying infrastructure.

What is HashiCorp Nomad?

Nomad is an open-source, flexible, and intuitive cluster manager and scheduler designed by HashiCorp. It uses declarative configuration syntax to define jobs, which are units of work that can be executed on a cluster of nodes. Jobs can be configured to run on any combination of resources, including Docker containers, virtual machines, and bare metal servers. Nomad automatically handles scheduling, resource allocation, and load balancing, ensuring that jobs are deployed and scaled according to their requirements.

Nomad is often used by organizations that are looking for a lightweight, easy-to-use container orchestration platform that can run on any infrastructure, including public and private clouds, as well as on-premises data centers. It is particularly well suited for organizations that are already using other HashiCorp tools as it integrates seamlessly with them.

Nomad components and architecture

Note the following Nomad components:

  • Agent—A Nomad process that operates in either server or client mode.
  • Client—Responsible for executing the tasks allocated to it. It registers itself with the servers and monitors for potential assignments. When operating the agent, the client is sometimes called a node.
  • Server—Oversees all jobs and clients, keeps track of tasks, and determines the allocation of tasks to different client nodes. The servers replicate data among themselves to guarantee high availability.
  • Dev agent—A specialized agent configuration that offers convenient defaults for operating a single-node Nomad cluster. It functions in both server and client mode and does not retain its cluster state on disk, enabling the agent to begin from a consistently clean state without needing to eliminate the disk-based state between executions.
High level architecture overview

High level architecture overview

How does Nomad work?

Nomad operates using a client–server architecture. The server nodes are responsible for managing the cluster state, while the client nodes are responsible for running workloads. When deploying an application, the user provides a declarative job specification that describes the desired state of the application. Nomad then schedules the workloads onto client nodes based on resource availability, constraints, and other factors.

These jobs and parameters can all be managed by infrastructure as code, using solutions like HashiCorp's Terraform, an extremely popular IaS platform.

Downloading and launching Nomad

Nomad is a self-contained lightweight executable that requires no installation. After downloading Nomad, add it to the PATH of your respective operating system. That's it. Once you have the executable in your PATH on Windows, you can run nomad.exe and start scheduling resources and applications.

To run Nomad, simply execute the following command from a command or terminal prompt:

nomad
Running the nomad executable

Running the nomad executable

Running the Nomad dev instance

One of the great features of HashiCorp Nomad is that it allows developers to run a local development environment in a single command with a UI, allowing easy job scheduling and resource creation. In my example, Nomad is running as a single-node cluster.

To start the single-node Nomad cluster, run the following command:

nomad agent -dev
Running a Nomad development environment

Running a Nomad development environment

The Nomad single-cluster development environment will launch, displaying the listener address and port.

Nomad development environment addresses and ports

Nomad development environment addresses and ports

Using a web browser, you will browse to the address and port of the local Nomad UI listener found at the following URL: http://127.0.0.1:4646

The Nomad UI provides developers with an interactive experience scheduling workloads with a GUI-driven interface.

Navigating to the Nomad web UI

Navigating to the Nomad web UI

If you click on your clients (see screenshot below), the client menu will open, and you will get a list of drivers Nomad has to work with on your Nomad host, including Docker, Java, QEMU, and others. In addition, the Nomad interface will indicate whether the specific driver is detected for use in scheduling.

Driver status on the Nomad host

Driver status on the Nomad host

In the Nomad UI, click the Jobs menu. The Jobs menu allows you to create jobs or tasks as scheduled work for the Nomad worker nodes. You can find example code snippets for Nomad example jobs here.

Below, we are submitting a test job using the example code pytechco-redis.nomad.hcl provided by HashiCorp to launch a Redis database using the Docker scheduler.

job "pytechco-redis" {
  type = "service"

  group "ptc-redis" {
    count = 1
    network {
      port "redis" {
        to = 6379
      }
    }

    service {
      name     = "redis-svc"
      port     = "redis"
      provider = "nomad"
    }

    task "redis-task" {
      driver = "docker"

      config {
        image = "redis:7.0.7-alpine"
        ports = ["redis"]
      }
    }
  }
}

Like other HashiCorp solutions, such as Terraform, Nomad jobs follow the workflow of Plan and then Run. Once you paste the code in the job window, you run the Plan option. This option validates the syntax and ensures that the job will run.

Running a job plan in the Nomad UI

Running a job plan in the Nomad UI

After running the Plan option, the UI allows you to Run the job. The warning below is returned because other drivers are missing from the host. However, this does not affect the running of the Redis container job. Click Run.

Running the Nomad job after the plan operation

Running the Nomad job after the plan operation

With the Run option executed, the Nomad scheduler has successfully scheduled the Redis Docker container.

The Redis container is launched by the Nomad scheduler

The Redis container is launched by the Nomad scheduler

You can see the Redis container running on your Nomad host if you issue a docker ps command from the command or terminal prompt. It validates that Nomad has successfully scheduled and orchestrated the launch of the Redis Docker container. You can now connect to the Redis container over the expected TCP port 6379.

Subscribe to 4sysops newsletter!

Viewing the Redis container from a docker ps command

Viewing the Redis container from a docker ps command

Wrapping up

HashiCorp Nomad has a lot of potential for many organizations that have been challenged by other container orchestrators, including Kubernetes. Like other HashiCorp solutions, Nomad is a single self-contained executable that enables scheduling various kinds of job tasks, including virtual machines, containers, and even applications. With the quick and easy "agent -dev" flag, developers can easily stand up a single-node Nomad cluster for developing their applications locally.

0 Comments

Leave a reply

Your email address will not be published.

*

© 4sysops 2006 - 2023

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account