DEV Community

Liem Le Hoang Duc
Liem Le Hoang Duc

Posted on • Edited on

HashiCorp Nomad Introduction

Oh, yeah???

P/s: I'm not telling to use HashiCorpNomad and abandoned K8S, but at least, take a look at it, you may think God is not abandoned you, no more!

TL;DR

  • Nomad is the project from HashiCorp, a company that help me, and a lot of other guys, working with Cloud more easily.
  • It was a workload orchestrator.
  • It support container application, legacy application, Java, Batch Job, QEMU.
  • It's easy to operate and maintain.
  • It had less magic than k8s, actually, no magics.
  • It's may be what you want from the very beginning but other guys just bark about K8S and told you to use K8S.

Use cases

  • You're working with legacy system, which is not ready to one-step move to Cloud.
  • You're not familiar with Orchestrator and Containerized application.
  • You're not familiar with Cloud, or you don't want to learn K8S.
  • You cannot use K8S because you don't have an OPs team, and your country don't have a K8S provider which you trusted.
  • You want to try out something differences than K8S.

Facts

In facts, some company combine K8S and Nomad together to handle their workload. Learn about it here

Terms

Nomad Server

This one will operate and checking the state of system. For example:
"Is this app in state that user defined?" If not, reschedule it!
"I need 1GB of RAM for my app, can you handle it?" Agent-X have enough memory, Ok, I will run your app on it!

To start a nomad server:
nomad agent -server -bind=0.0.0.0 -data-dir=/tmp/nomad-server

Nomad Agent

This one will listen to Server request and reporting the state of application to Server, if the state of the application is abnormal, Server will request Agent to stop/start/restart the application.

To start a nomad agent:
nomad agent -agent -data-dir=/tmp/nomad-agent

Notes:

On local machine, I usually use nomad agent -dev to bootstrap nomad cluster. Think about K8S 🙃

Job

Is the configuration which is defined the expected state, which you want your app into.

A job file usually have following structure:

job
  \_ group
        \_ task

Example:

Group

Is a collection of application which will be scheduled on the same Agent.
Application in the same group can be shared volume and network (using Consul Connect).
Pro tips: Using group as your unit of scaling.
Bonus For people come from K8S, using group as your Pod will be good enough. Combine group with difference type of Job will provide things similar to Deployment, DaemonSet.
Example:

Task

Is a unit of work which was your application. Say container, binary, Java app.
Pro tips: Naming your task follow your job will help you debug and managing/monitoring application more easily and friendly. Eg: Your job name is "example", then your nginx should named "example-nginx".
Example:

Service

Note: This is a bit out of Nomad, becuz you will need Consul to let this work. But, who use Nomad without Consul?
After you start your application, say, an API and you want to populate its address to other services over Consul, you can use this stanza instead of self register inside your code.
Example:

Conclusion:

That enough for the introduction. As a developer, you can get use of Nomad right away.
In the next post, I will show you how to create a website using Docker, Traefik and Nomad.

For people who dont have patience. Come here with a full source code how to deploy a web using Nomad, Traefik and Docker as well as how to bootstrap Nomad Cluster using Ansible.

https://github.com/liemle3893/nomad-getting-started

Top comments (0)