Back to home

Setup nomad cluster with Vagrant

Setup nomad cluster with Vagrant
RN

Rizqy Nugroho

Time to read

~ 3 minutes

Published

Dec 24, 23

Introduction:

Nomad, an open-source cluster manager and scheduler by HashiCorp, simplifies the deployment and management of applications at scale. Setting up a Nomad cluster in development mode is an excellent way to explore its features and functionality in a controlled environment. In this guide, we'll walk through the steps to help you establish a Nomad cluster on your local machine for development purposes.

Prerequisites:

Before we begin, ensure you have the following prerequisites installed on your machine:

  1. Vagrant: Vagrant is a tool for managing virtualized development environments.
  2. VirtualBox or another provider supported by Vagrant: This will be used to run the virtual machines.

Step 1: Install Vagrant and VirtualBox

Download and install Vagrant from the official website: Vagrant Downloads.

Install a virtualization provider like VirtualBox: VirtualBox Downloads.

Step 2: Create a Vagrantfile

Create a new directory for your Nomad cluster and navigate to it. Create a file named Vagrantfile with the following content:

Vagrant.configure("2") do |config|
  (1..3).each do |i|
    config.vm.define "nomad-node-#{i}" do |node|
      node.vm.box = "ubuntu/bionic64"
      node.vm.network "private_network", type: "dhcp"
      node.vm.provider "virtualbox" do |vb|
        vb.memory = "512"
      end
    end
  end
end

This configuration sets up a simple cluster with three nodes.

Step 3: Start the Virtual Machines

In the terminal, navigate to the directory containing the Vagrantfile and run:

vagrant up

This command will create and start the virtual machines based on the configuration.

Step 4: Install Nomad

SSH into each virtual machine and install Nomad. Run the following commands for each node:

vagrant ssh nomad-node-1
sudo apt-get update
sudo apt-get install -y nomad

Repeat these commands for nomad-node-2 and nomad-node-3.

Step 5: Configure Nomad

Create a Nomad configuration file on each node. For example, create a file named nomad.hcl with the following content:

data_dir = "/var/lib/nomad"

server {
  enabled = true
  bootstrap_expect = 3
}

client {
  enabled = true
}

Step 6: Start Nomad Servers

On nomad-node-1, run:

sudo nomad agent -config=nomad.hcl

On nomad-node-2 and nomad-node-3, run:

sudo nomad agent -config=nomad.hcl -server -join=<IP_ADDRESS_OF_NOMAD_NODE_1>

Replace <IP_ADDRESS_OF_NOMAD_NODE_1> with the actual IP address of nomad-node-1.

Step 7: Verify Cluster Status

Check the status of the Nomad cluster by running the following command on any of the nodes:

nomad server members

You should see information about the three Nomad servers.

Conclusion:

Congratulations! You've successfully set up a Nomad cluster in development mode. This guide provides a basic foundation for understanding Nomad's cluster architecture and how it manages tasks across multiple nodes. Feel free to explore more advanced configurations and Nomad features to enhance your understanding of this powerful orchestration tool.