Getting started with Nomad

Nomad is a workload orchestrator built by HashiCorp. But what is a workload orchestrator? For instance, let us say you have an application that needs to be deployed. Ideally, you will find a server with the necessary resource allocation needed by the application, deploy the code in it, set up networking, manage the lifecycle of the application, etc. Handling all these manually will not enable us to scale our application. To achieve all these with ease, orchestrators comes to our rescue.

By setting up a cluster of nodes and installing orchestrators like Nomad in each of the nodes, will take care of

  1. Deploying applications
  2. Resource allocations
  3. Monitor progress & etc.,

Nomad was built with the goal to reduce the interaction between the development team and the operations team. Developers will just write a job file and submit it to the Nomad server which then will take care of scheduling by abstracting away the underlying operational aspects of infrastructure.

Architecture

Nomad runs in a cluster that involves a client-server setup. At the minimal, we can set up a single node cluster which acts as both server and client(which is recommended only for development mode). For production, we need at least 3 to 5 (but not more than 7) servers and number of client agents to ensure scaling, the persistence of state, etc.,

Nomad combines a lightweight resource manager and a sophisticated scheduler. One other interesting feature of Nomad is that it can link and maintain clusters from multiple regions in any cloud provider. This enables us to overcome any instance of failure or data loss. Nomad is also cloud-agnostic.

Sounds like Kubernetes, ECS?

oh-ho! Doesn’t it sound like the other container orchestrators - Kubernetes, ECS? The answer is yes and no. Nomad does most of the things like other orchestrators but also stands out in many ways. Unlike other orchestrators, which can schedule only containerized applications, Nomad can be used to schedule legacy, virtualized, containerized applications. Nomad is also lightweight, modern and comes as a single binary, whereas Kubernetes is a collection of many inter-operating services that together provides full functionality. Nomad can be easily integrated with other HashiCorp products like Consul for service discovery, Vault for secret management

Deploy & Manage using Nomad

To install Nomad in your local refer to this link. For demo purposes, we can run single-node architecture where the server and client run on the same machine.

Starting the agent

To set up the nomad agent, run

After it runs successfully, we can figure out from the logs that the agent is running in both client and server mode and has claimed leadership of the cluster.

To check the status of the node:

To stop this agent just use Ctrl+C, which will gracefully shutdown the agent.

Submitting a Job

Nomad accepts the description of the application that needs to be deployed in the form of a file called Job file. Job file can be specified either in Hashicorp Configuration Language(HCL) or JSON.

Let us create a job file called hello-tenant.nomad which will hold the job description in JSON format.

In the above example, we have specified a group which is a collection of tasks. Nomad co-locates all the tasks within a group to the same Nomad client. We have defined only one task which uses Docker driver. There are many drivers available that will cater to different types of workloads. You can find the driver list here.

We have to specify the Docker image name inside config. The resources section includes memory and network specifications. We can also pass environment variables using the env section.

To see a dry-run of what will happen if this job file is submitted, run

To submit the job to nomad agent, run

To see the status of the job,

Alternatively, we can use Nomad UI to manage the entire cluster. UI can be triggered from the command line using:

This command will open the Nomads Web UI in your browser like below

We can even create and submit jobs from UI instead of the command line.

We can check for allocation status using:

Demonstrated above is a simple example to get started with Nomad. We can do much more than this. Happy exploring Nomad!

Francium Tech is a technology company laser focused on delivering top quality software of scale at extreme speeds. Numbers and Size of the data don’t scare us. If you have any requirements or want a free health check of your systems or architecture, feel free to shoot an email to contact@francium.tech, we will get in touch with you!